读取XML文件问题!! [英] Reading XML file problem!!
本文介绍了读取XML文件问题!!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
读取XML文件时遇到问题
我正在使用XmlDocument,请往下看,需要一些帮助.
在这一点上,我让ChildNodes计数为零,应该有更多的
我做错了什么?
有问题的xml
I am having a problem while reading an XML file
I am using XmlDocument, look down, need some help please.
At a point i get ChildNodes count zero, where there should be more
What am i doing wrong??
The xml in question
<?xml version="1.0" standalone="yes"?>
<RequestDataSet xmlns="http://tempuri.org/RequestDataSet.xsd">
<tZahtjevZaOvjeravanje_Zaglavlje>
<ID>-1</ID>
<IDOvlastenogServisa>128</IDOvlastenogServisa>
<PredlozeniDatumPregleda>2011-08-04T09:20:00+02:00</PredlozeniDatumPregleda>
<StvarniDatumPregleda>2011-08-02T09:19:59.953125+02:00</StvarniDatumPregleda>
<TipZahtjeva>OVJERU MJERILA</TipZahtjeva>
<BrojZahtjeva>1108</BrojZahtjeva>
<GodinaZahtjeva>2011</GodinaZahtjeva>
<IDInstitucije>1</IDInstitucije>
<Ukupno>0</Ukupno>
<Status>100</Status>
</tZahtjevZaOvjeravanje_Zaglavlje>
<tZahtjevZaOvjeravanje_Detalji>
<ID>-1</ID>
<IDZaglavlja>-1</IDZaglavlja>
<RBR>1</RBR>
<SifraMjerila>1541</SifraMjerila>
<TOM>PT600</TOM>
<Proizvodjac>Sartorius</Proizvodjac>
<MjernoPodrucjeOd>5 g</MjernoPodrucjeOd>
<MjernoPodrucjeDo>610 g</MjernoPodrucjeDo>
<SOT_Grupa>M</SOT_Grupa>
<SOT_Podgrupa>2</SOT_Podgrupa>
<SOT_BrojOdobrenja>17</SOT_BrojOdobrenja>
<SerijskiBroj>50705650</SerijskiBroj>
<NazivKorisnika>Omega</NazivKorisnika>
<AdresaKorisnika>Zagreb, Babonićeva 59</AdresaKorisnika>
<MjestoPregleda>OS Libra tehničar Zagreb, II. Praćanska 6/A</MjestoPregleda>
<SOZ_Drzava>HR</SOZ_Drzava>
<NOZ_Drzava>HR</NOZ_Drzava>
<NOZ_Institucija>1</NOZ_Institucija>
<TipZahtjeva>R</TipZahtjeva>
<BrojIzvjesca>010817</BrojIzvjesca>
</tZahtjevZaOvjeravanje_Detalji>
</RequestDataSet>
这是应该在xml中读取值的代码,但正如我所说的,它说没有节点!?
Here is the code that is supposed to read values within the xml but as i said it says there are no nodes!?
Try
Dim xmld1 As XmlDocument
Dim nodelist1 As XmlNodeList
Dim nodes1 As XmlNode
xmld1 = New XmlDocument()
xmld1.Load(rxml)
nodelist1 = xmld1.SelectNodes("/RequestDataSet/tZahtjevZaOvjeravanje_Detalji")
'OK, AT THIS POINT I HAVE ChildNodes Count 0
'HERE GOES THE REST OF THE CODE THAT DOESN'T HAVE ANY XML IN IT
Catch ex As Exception
MsgBox(ex.ToString)
End Try
在此先感谢
Thanks in advance
推荐答案
我不认为您想要标准XML文件中的xmlns
标记-如果我删除了xmlns="http://tempuri.org/RequestDataSet.xsd"
它将起作用. .
是的,但是xml文件是由其他软件生成的.也许我可以尝试通过一些字符串文件操作来删除标记"
I don''t think you want thexmlns
tag in a standard XML file - if I remove thexmlns="http://tempuri.org/RequestDataSet.xsd"
it works...
"yes, but the xml file is generated by another software. maybe if i could try removing the tag with some string-file manipulation"
Regex removeXmlnsAttribute = new Regex("\\sxmlns=\".*?\"");
string result = removeXmlnsAttribute.Replace(InputText,regexReplace);
Dim removeXmlnsAttribute As New Regex("\sxmlns="".*?""")
Dim result As String = removeXmlnsAttribute.Replace(InputText, regexReplace)
尝试 HtmlAgilityPack
http://htmlagilitypack.codeplex.com/ [ ^ ]
它比Microsoft XMLDocument好得多.它忽略了无法理解的部分,并且根本不需要删除非XML标签.
Try HtmlAgilityPack
http://htmlagilitypack.codeplex.com/[^]
It''s very better than Microsoft XMLDocument. It ignores the sections that couldn''t be understood and simply there is no need to remove non XML tags.
这篇关于读取XML文件问题!!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文