Regex: inserting a namespace

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I do this with regular expressions...

Find "<Invoice>" or "<CreditNote>" or "<OrderConfirmation>" and replace it
with "<Invoice xmlns="MyNamespace">" or "<CreditNote xmlns="MyNamespace">" or
"<OrderConfirmation xmlns="MyNamespace">" respectively.

If possible, only do this the 1st match.

Thanks,
Craig
 
I am curious as to why this HAS to be regex. With the XML features of .NET
and a simple XPath query, you can find the node(s) in question and add the
attributes. This is not impossible, in Regex, by any means (Regex.Replace),
but I am not sure stepping outside of the XML box offers much, if anything.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
Back
Top