5

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#?

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. Used a mixture of these links and this: stackoverflow.com/questions/1778299/… Works fine.
0

Use http://msdn.microsoft.com/en-us/library/system.xml.xmlnamespacemanager.addnamespace.aspx

1 Comment

Don't quite see this - how to add the namespace prefix to each element this way?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.