0

I am working on the XML files in C#.

I want to extact the name space and do some maniplations.

say my xml file looks like this.

        <Content xmlns="http://ABCD.com/sdltridion/schemas/XXXXX">
            <first>ABCD</first>
            <second>DCEF</second>
        </Content>

I want to extract Xml namespace from the root tag, ang get the value of XXXXX.

Output needed: XXXXX

Can any one help regarding this.

Thank you.

ThinkingStiff
  • 64,767
  • 30
  • 146
  • 239
Patan
  • 17,073
  • 36
  • 124
  • 198

2 Answers2

2

Try this:

var xdoc = XDocument.Parse(xml);
var ns = xdoc.Root.Name.Namespace.NamespaceName;
var value = new Uri(ns).Segments.LastOrDefault();
Oleks
  • 31,955
  • 11
  • 77
  • 132
0

You can try XNamespace class

 XNamespace ns = XNamespace.Get("http://ABCD.com/sdltridion/schemas/XXXXX");
 var result = XElement.Load("URL").Descendants(ns + "NODENAME"); 

Thanks

Deepu

Deepu Madhusoodanan
  • 1,495
  • 1
  • 14
  • 26