How to retrieve the corresponding values from XML file in vb.net?

  • Thread starter Thread starter Xenis
  • Start date Start date
X

Xenis

Guest
I need to Retrieve the values from a XML file i have seen many example but none of them is like the XML I have.
My XML look like this .

<title>TOSSICOLOGIA D'ABUSO</title>
<component>
<section>
<code code="31011" codeSystemName="Codifica Interna Laboratorio" displayName="Etanolo (urine)">
<!--TRASCODIFICA ANALISI NON DISPONIBILE-->
</code>
<text>
<paragraph>
</paragraph>
<table>
<thead>
<tr>
<th>Esame</th>
<th>Esito</th>
<th>Abnormal Flag</th>
<th>Unita di misura</th>
<th>Range di riferimento</th>
<th>Metodo</th>
</tr>
</thead>
<tbody>
<tr>
<td>Etanolo (urine)</td>
<td>&lt; 0,01 g/l</td>
<td></td>
<td></td>
<td>fino a 0,35</td>
<td />
</tr>
</tbody>
</table>
<footnote></footnote>
<paragraph>
</paragraph>
<!--Inizio Microbiologia sezione humane readable-->
<!--Fine Microbiologia sezione humane readable-->
</text>
<entry typeCode="DRIV">
<!-- INIZIO MONO RISULTATO -->
<act classCode="ACT" moodCode="EVN">
<code code="31011" codeSystemName="Codifica Interna Laboratorio" displayName="Etanolo (urine)">
<!--TRASCODIFICA ANALISI NON DISPONIBILE-->
</code>
<statusCode code="completed" />
<!--(INIZIO) GESTIONE MICROBIOLOGIA MONO RISULTATO -->
<!--(FINE) GESTIONE MICROBIOLOGIA MONO RISULTATO -->
<entryRelationship typeCode="COMP">
<observation classCode="OBS" moodCode="EVN">
<code code="31011" codeSystemName="Codifica Interna Laboratorio" displayName="Etanolo (urine)">
<!--TRASCODIFICA RISULTATI NON DISPONIBILE-->
<!--ANL_COMPLETED-->
</code>
<statusCode code="completed" />
<effectiveTime value="20170216131204" />
<value xsi:type="ST">&lt; 0,01 g/l</value>
<!---->
<referenceRange typeCode="REFV">
<observationRange classCode="OBS" moodCode="EVN.CRT">
<value xsi:type="IVL_PQ">
<low value="0.00" />
<high value="0.35" />
</value>
<interpretationCode code="N" />
</observationRange>
</referenceRange>
<referenceRange typeCode="REFV">
<observationRange classCode="OBS" moodCode="EVN.CRT">
<value xsi:type="ST">fino a 0,35</value>
<interpretationCode code="N" />
</observationRange>
</referenceRange>
</observation>
</entryRelationship>
<!-- VAL USED -->
</act>
<!-- FINE MONO RISULTATO -->
</entry>
</section>
</component>
<component>
<section>
<code code="32000" codeSystemName="Codifica Interna Laboratorio" displayName="Creatininuria">
<!--TRASCODIFICA ANALISI NON DISPONIBILE-->
</code>
<text>
<paragraph>
<content ID="ANLNOTE---2-2">Prova autenticità campione droghe</content>
</paragraph>
<table>
<thead>
<tr>
<th>Esame</th>
<th>Esito</th>
<th>Abnormal Flag</th>
<th>Unita di misura</th>
<th>Range di riferimento</th>
<th>Metodo</th>
</tr>
</thead>
<tbody>
<tr>
<td>Creatininuria</td>
<td>193.0</td>
<td></td>
<td>mg/dL</td>
<td>fino a 20: campione non idoneo
(non utilizzabile ai fini medico legali)
20 - 40: campione dubbio
sup. a 40: campione idoneo
</td>
<td />
</tr>
</tbody>
</table>
<footnote></footnote>
<paragraph>
</paragraph>
<!--Inizio Microbiologia sezione humane readable-->
<!--Fine Microbiologia sezione humane readable-->
</text>
<entry typeCode="DRIV">
<!-- INIZIO MONO RISULTATO -->
<act classCode="ACT" moodCode="EVN">
<code code="32000" codeSystemName="Codifica Interna Laboratorio" displayName="Creatininuria">
<!--TRASCODIFICA ANALISI NON DISPONIBILE-->
</code>
<statusCode code="completed" />
<!--(INIZIO) GESTIONE MICROBIOLOGIA MONO RISULTATO -->
<!--(FINE) GESTIONE MICROBIOLOGIA MONO RISULTATO -->
<entryRelationship typeCode="SUBJ">
<act classCode="ACT" moodCode="EVN">
<code code="48767-8" codeSystem="2.16.840.1.113883.6.1" codeSystemName="LOINC" displayName="Annotation Comment" />
<text>
<reference value="ANLNOTE---2-2" />
</text>
</act>
</entryRelationship>
<entryRelationship typeCode="COMP">
<observation classCode="OBS" moodCode="EVN">
<code code="32000" codeSystemName="Codifica Interna Laboratorio" displayName="Creatininuria">
<!--TRASCODIFICA RISULTATI NON DISPONIBILE-->
<!--ANL_COMPLETED-->
</code>
<statusCode code="completed" />
<effectiveTime value="20170216121035" />
<value xsi:type="PQ" value="193.0" unit="mg/dL" />
<referenceRange typeCode="REFV">
<observationRange classCode="OBS" moodCode="EVN.CRT">
<value xsi:type="IVL_PQ">
<low value="40.0" unit="mg/dL" />
<high value="99999.0" unit="mg/dL" />
</value>
<interpretationCode code="N" />
</observationRange>
</referenceRange>
<referenceRange typeCode="REFV">
<observationRange classCode="OBS" moodCode="EVN.CRT">
<value xsi:type="ST">fino a 20: campione non idoneo
(non utilizzabile ai fini medico legali)
20 - 40: campione dubbio
sup. a 40: campione idoneo
</value>
<interpretationCode code="N" />
</observationRange>
</referenceRange>
</observation>
</entryRelationship>
<!-- VAL USED -->
</act>
<!-- FINE MONO RISULTATO -->
</entry>
</section>


As you can see is like a html table.I have create a table in database with those
FIELDS name, and i need to put the values of the fields in database.

But first of all i need a way how to get the VALUES using visual basic and later on to see how to put the value on db.
So this is the image that tell the value i need are under tag ,,td'' at the XML.



For this part of the question i can use and it works for one element only .buti need to get all the values from my xml file.

Dim path As String = "C:\Users\ShkelzenTarja\projekt\CDR_v3_1\CDR\test2.xml" ' "put path to xml file here"
Dim xe As XElement
xe = XElement.Load("C:\Users\ShkelzenTarja\projekt\CDR_v3_1\CDR\test2.xml")
Dim sectn As XElement = (From el In xe...<code> Select el Take 1).FirstOrDefault

If sectn IsNot Nothing Then 'did we get a code
'yes
sectn = sectn.Parent 'the section
'
End If
If sectn IsNot Nothing Then 'did we get a section
'yes
For Each tr As XElement In sectn...<table>.<tbody>.<tr>
For Each td As XElement In tr.<td>
Debug.WriteLine(td.Value)
Next
Next

End If


but i have some question :

1- the diff of path and xe = XElement.Load

2- Select el Take 1).FirstOrDefault ... how can i change this in order to get all the values the document has and not only the first one .


3- should i use the same sintax if my xml has two title because in fact it has is a whole document.
Thank you for your help

sh

Continue reading...
 
Back
Top