Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <Main version="1.0" xmlns="urn:root:v1">
  3. <Report>
  4. <Title>Some Value</Title>
  5. </Report>
  6. <Content>
  7. <Address>
  8. <CountryName xmlns="urn:location:v2">Australia</CountryName>
  9. </Address>
  10. </Content>
  11. </Main>
  12.  
  13. <?xml version="1.0" encoding="utf-8"?>
  14. <root:Main version="1.0" xmlns:root="urn:root:v1" xmlns:loc="urn:location:v2">
  15. <root:Report>
  16. <root:Title>Some Value</root:Title>
  17. </root:Report>
  18. <root:Content>
  19. <root:Address>
  20. <loc:CountryName>Australia</loc:CountryName>
  21. </root:Address>
  22. </root:Content>
  23. </root:Main>
  24.  
  25. XDocument doc = XDocument.Load(@"C:TempSource.xml");
  26.  
  27. var content = XElement.Parse(doc.ToString());
  28.  
  29. content.Attributes("xmlns").Remove();
  30.  
  31. content.Add(new XAttribute(XNamespace.Xmlns + "root", "urn:root:v1"));
  32. content.Add(new XAttribute(XNamespace.Xmlns + "loc", "urn:location:v2"));
  33.  
  34. foreach (var node in doc.Root.Descendants().Where(n => n.Name.NamespaceName == "urn:location:v2"))
  35. {
  36. node.Attribute("xmlns").Remove();
  37. node.Add(new XAttribute(XNamespace.Xmlns + "loc", "urn:location:v2"));
  38. }
  39.  
  40. content.Save(@"C:TempTarget.xml");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement