Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="utf-8"?>
- <Main version="1.0" xmlns="urn:root:v1">
- <Report>
- <Title>Some Value</Title>
- </Report>
- <Content>
- <Address>
- <CountryName xmlns="urn:location:v2">Australia</CountryName>
- </Address>
- </Content>
- </Main>
- <?xml version="1.0" encoding="utf-8"?>
- <root:Main version="1.0" xmlns:root="urn:root:v1" xmlns:loc="urn:location:v2">
- <root:Report>
- <root:Title>Some Value</root:Title>
- </root:Report>
- <root:Content>
- <root:Address>
- <loc:CountryName>Australia</loc:CountryName>
- </root:Address>
- </root:Content>
- </root:Main>
- XDocument doc = XDocument.Load(@"C:TempSource.xml");
- var content = XElement.Parse(doc.ToString());
- content.Attributes("xmlns").Remove();
- content.Add(new XAttribute(XNamespace.Xmlns + "root", "urn:root:v1"));
- content.Add(new XAttribute(XNamespace.Xmlns + "loc", "urn:location:v2"));
- foreach (var node in doc.Root.Descendants().Where(n => n.Name.NamespaceName == "urn:location:v2"))
- {
- node.Attribute("xmlns").Remove();
- node.Add(new XAttribute(XNamespace.Xmlns + "loc", "urn:location:v2"));
- }
- content.Save(@"C:TempTarget.xml");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement