Read XML with namespace

using System.Xml.Linq;
using System.Xml.XPath;
using System.Xml;




            string myxml =
           @"<e:root xmlns:e='http://kidd.com'>
                <e:one xmlns:a='http://rediff.com'>
                    <a:oneone xmlns:b='http://yahoo.com'>
                        <b:id>1</b:id>
                        <b:name></b:name>
                    </a:oneone>
                    <a:twotwo xmlns:b='http://orkut.com'>
                        <b:id>1</b:id>
                        <b:name></b:name>
                    </a:twotwo>
                </e:one>
              </e:root>";



            XElement elem = XElement.Parse(myxml);

            XNamespace nsr = "http://rediff.com";
            XNamespace nsy = "http://yahoo.com";
            XNamespace nse = "http://kidd.com";

            string t = elem.Element(nse + "one").Element(nsr + "oneone").Element(nsy + "id").Value;

            Response.Output.Write("Value of id within oneone: {0}", t);


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章