Click here to Skip to main content
16,020,186 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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
<?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>


Here is the code that is supposed to read values within the xml but as i said it says there are no nodes!?

VB
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
Posted

I don't think you want the xmlns tag in a standard XML file - if I remove the xmlns="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"

C#
Regex removeXmlnsAttribute = new Regex("\\sxmlns=\".*?\"");
string result = removeXmlnsAttribute.Replace(InputText,regexReplace);


VB
Dim removeXmlnsAttribute As New Regex("\sxmlns="".*?""")
Dim result As String = removeXmlnsAttribute.Replace(InputText, regexReplace)
 
Share this answer
 
v2
Comments
Holc 16-Oct-11 4:52am    
yes, but the xml file is generated by another software. maybe if i could try removing the tag with some string-file manipulation
OriginalGriff 16-Oct-11 4:57am    
Good idea - it's not difficult to do with a basic regex...
OriginalGriff 16-Oct-11 5:04am    
Answer updated
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.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900