zoukankan      html  css  js  c++  java
  • 【xml]: Read XML with Namespace resolution using XLinq.XElement

    http://www.codeproject.com/KB/linq/xelementns.aspx

     string myxml =
                @"<root>
                    <one xmlns:a='http://rediff.com'>
                        <a:oneone  sequenceId= '11' 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>
                    </one>
                  </root>
    ";

              XNamespace nsr = "http://rediff.com";
              XNamespace nsy = "http://yahoo.com";
           
                XElement elem = XElement.Parse(myxml);   

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

               string sequenceId = elem.Element("one").Element(nsr + "oneone").Attribute("sequenceId").Value;


               XDocument doc = new XDocument();
               doc = XDocument.Parse(myxml);

               XElement docElement = doc.Descendants(nsr + "oneone").FirstOrDefault();

               string t1 = docElement.Element(nsr + "oneone").Element(nsy + "id").Value;

               string sequenceId1 = docElement.Element(nsr + "oneone").Attribute("sequenceId").Value;
    做个快乐的自己。
  • 相关阅读:
    Java自学第十天
    Java自学第九天
    Java自学第八天
    Java自学第七天
    Java自学第六天
    Java自学第五天
    Java自学第四天
    Java自学第三天
    Oracle11g RAC单节点重启
    PostgreSQL 日志处理
  • 原文地址:https://www.cnblogs.com/Jessy/p/2244306.html
Copyright © 2011-2022 走看看