串我曾经在一个文件中的以下XML(简体):解析与VB.Net复杂的XML:元素注入取决于命名空间
<?xml version="1.0" encoding="ISO-8859-1"?>
<XCer xmlns="http://x.y.z" xmlns:xsi="http://www.x.y.z" xsi:schemaLocation="http://www.x.y.z" track_id="559" mp_id="398" sub_id="569">
<capability xsi:type="XCracT">
<type>rec</type>
<sub_type>pc</sub_type>
<action>reco</action>
</capability>
<final_result OD="DGS=1.6" creator="Creator1" version="1.11" xsi:type="XCarT">
<code>300000000</code>
<code_cnf>0.7454</code_cnf>
<code_attr>seq</code_attr>
<status_attr>fdos</status_attr>
<text>this text</text>
<standardized_text>other text</standardized_text>
<region>
<type>add</type>
<symbology>machine</symbology>
</region>
</final_result>
<final_result OD="DGS=1.7" creator="Creator2" version="1.11" xsi:type="XCarT">
<code>3040280100015</code>
<code_cnf>0.7454</code_cnf>
<code_attr>seq</code_attr>
<status_attr>fdos</status_attr>
<text>this text</text>
<standardized_text>other text</standardized_text>
<region>
<type>add</type>
<symbology>machine</symbology>
</region>
<polygon>
<dot x="849" y="1600"/>
<dot x="823" y="1600"/>
<dot x="819" y="1166"/>
<dot x="845" y="1166"/>
</polygon>
</final_result>
</XCer>
在一个非常基本的水平,我想创建3个变量:创造者,代码,mp_id,并填写最终结果OD =“DGS = 1.6”部分的细节,即'Creator1','300000000','398'(来自第一个XCer元素)和'本文',但我的XML技能是尽管在过去的几天里尝试了几个速成课程,但索雷利仍然缺乏。
我已经试过了基本
Using reader As XmlReader = XmlReader.Create("C:\filename.xml")
while reader.Read()
if reader.IsStartElement() Then
If reader.Name = "code" Then
code = reader.ReadElementContentAsString()
这让我的代码,但我不能行
final_result OD="DGS=1.6" creator="Creator1" version="1.11" xsi:type="XCarT">
中得到任何的元素,我不能限制我想要的码元该子树不会覆盖前面的代码。
这是梦幻般的史蒂芬,我已经放弃了一些已放弃的NameSpaceManager尝试,因为我无法正确定义SelectSingleNode的第一部分。是否有关于如何生成字符串“/x:XCer[1]/x:final_result[@OD='DGS=1.6']/@creator”的文档的好来源? – foreachin 2013-05-10 13:32:32
不幸的是,我没有任何建议最好去学习XPath。我通过一些O'Reilly关于XSLT的书(它主要依赖于XPath)了解了它,但我相信有更好的书籍和站点可供学习XPath。我只需在Web上搜索XPath并查看您的兴趣。 – 2013-05-10 14:04:38