Reputation: 2687
I have an XML document from which I need to extract a nodeset and add a namespace. So, from a doc I extract this:
<List>
<ListItem>
<SomeData>Here is some text</SomeText>
</ListItem>
<ListItem>
<SomeData>Here is some more text</SomeText>
</ListItem>
</List>
and need to create this:
<my:List xmlsns:my='http://SomeNamespace.org>
<my:ListItem>
<my:SomeData>Here is some text</my:SomeText>
</my:ListItem>
<my:ListItem>
<SomeData>Here is some more text</my:SomeText>
</my:ListItem>
</my:List>
There will be a variable quantity of list items and the elements might change and have different name, so I need a generic solution. Is there an easy way to do that in .Net C#?
Upvotes: 5
Views: 138
Reputation: 4264
Use http://msdn.microsoft.com/en-us/library/system.xml.xmlnamespacemanager.addnamespace.aspx
Upvotes: 0
Reputation: 22368
You can use XSLT for this. Check out this question: Add a namespace to elements
Use the .net class XslTransform to do this in code: http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=63
Upvotes: 3