VB.NET reading XML file troubles
I am using the following code to parse a XML file of mine:
Code:
Dim xml As String = "<?xml version=""1.0"" encoding=""Windows-1252""?>" & _
"<theref:theref-msg xmlns:csr=""http://www.xxxxx.com/Schema/csr"" xmlns:theref=""http://www.xxxxx.com/Schema/theref"">" & _
"<theref:header>" & _
"<theref:eid />" & _
"<theref:reference_id>429</theref:reference_id>" & _
"<theref:sr_type_code>US1</theref:sr_type_code>" & _
"<theref:event_type_code>REQUEST</theref:event_type_code>" & _
"<theref:eai_event_code>DSR</theref:eai_event_code>" & _
"<theref:source_code>WORKS</theref:source_code>" & _
"<theref:target_code>APP</theref:target_code>" & _
"<theref:status_code />" & _
"<theref:details />" & _
"</theref:header>" & _
"<theref:body>" & _
"<csr:document>" & _
"<csr:header>" & _
"<csr:system>CSR</csr:system>" & _
"<csr:doc_name>FULLSR</csr:doc_name>" & _
"<csr:version>3.1</csr:version>" & _
"<csr:dml_event>UPDATE</csr:dml_event>" & _
"</csr:header>" & _
"</csr:document></theref:body></theref:theref-msg>"
Dim document As XDocument = XDocument.Parse(xml)
Dim xmlb = (From getXMLData In document.<theref:theref-msg>.<theref:header>.<theref:body>.<csr:document>.<csr:header>).ToList()
I get a value of "0" from xmlb when i should get a "1" if it found something.
I can get the first half (<theref:header> to </theref:header>) using this command:
Code:
Dim xmlb = (From getXMLData In document.<theref:theref-msg>.<theref:header>).ToList()
Any help would be great! :)
David
Re: VB.NET reading XML file troubles
There's no reason to type in the xml as a string and then parse it.
Code:
Imports <xmlns:theref="http://www.xxxxx.com/Schema/theref">
Imports <xmlns:csr="http://www.xxxxx.com/Schema/csr">
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim doc = <?xml version="1.0" encoding="Windows-1252"?>
<theref:theref-msg xmlns:csr="http://www.xxxxx.com/Schema/csr" xmlns:theref="http://www.xxxxx.com/Schema/theref">
<theref:header>
<theref:eid/>
<theref:reference_id>429</theref:reference_id>
<theref:st_type_code>US1</theref:st_type_code>
<theref:event_type_code>REQUEST</theref:event_type_code>
<theref:source_code>WORKS</theref:source_code>
<theref:target_code>APP</theref:target_code>
<theref:status_code/>
<theref:details/>
</theref:header>
<theref:body>
<csr:document>
<csr:header>
<csr:system>CSR</csr:system>
<csr:doc_name>FULLSR</csr:doc_name>
<csr:version>3.1</csr:version>
<csr:dml_event>UPDATE</csr:dml_event>
</csr:header>
</csr:document>
</theref:body>
</theref:theref-msg>
Dim xmlb = (From x In doc...<csr:header>).ToList
End Sub
End Class
Re: VB.NET reading XML file troubles
Problem was that i had my imports incorrectly defined. All works now :)
David