2013-10-29 37 views
0

我正在写一个C#程序,它将从服务器获取数据,将其写入文件,然后读取文件以获取所包含的数据。 最后一部分是问题所在。我得到我的XML文件流和XML文件似乎很好,但除了根节点,我的程序不接受任何子节点,即使在列表中它计数所有700个子节点。正在检查我的拼写,地址,树...迄今没有任何工作。子节点不被接受

XML数据:

<?xml version="1.0" encoding="UTF-8"?> 
<uniprot xmlns="http://uniprot.org/uniprot" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://uniprot.org/uniprot http://www.uniprot.org/support/docs/uniprot.xsd"> 
    <entry dataset="Swiss-Prot" created="2005-03-01" modified="2013-10-16" version="51"> 
    <accession>P69430</accession> 
    <accession>O65938</accession> 
    <accession>P27856</accession> 
    <name>TATA_ECO57</name> 
    <protein> 
     <recommendedName> 
     <fullName>Sec-independent protein translocase protein TatA</fullName> 
     </recommendedName> 
    </protein> 

程序:

Datapath = startupPath + "\\" + Data[0, 0] + ".xml"; 
XmlDocument XMLdoc = new XmlDocument(); 
      XMLdoc.Load(Datapath); 
XmlNodeList xnList = XMLdoc.SelectNodes("//*"); //the list shows all 700 entries so the path etc are correct 
var node = XMLdoc.SelectSingleNode("uniprot/entry/protein/recommendedName/fullName").InnerText; 

当我试图从ADRESS UNIPROT任何子节点,它只是空驱动我疯了。任何人都可以帮忙吗?

回答

4

您是否尝试过使用命名空间?

 XmlDocument doc = new XmlDocument(); 
     XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable); 
     nsmgr.AddNamespace("ns", "http://uniprot.org/uniprot"); 
     var node = doc.SelectSingleNode("//ns:exampleNode", nsmgr); 
+0

它工作。谢谢你太多了。 – MeepMania

0

尝试这一个:XmlNode的节点= doc.SelectSingleNode( “// // UNIPROT条目/蛋白质/ recommendedName /全名”); node.InnerXml;