如何从vb.net的XML文件中检索相应的值?

时间:2018-11-15 14:54:09

标签: xml vb.net oracle

我需要从一个XML文件中检索值,我已经看到了很多示例,但是它们都不像我所拥有的XML。 我的XML看起来像这样。

model.fit(X_train, [Y_train[:,0:1], Y_train[:,1:]], ...)

您看到的就像一个html表。我已经在数据库中创建了一个表  FIELDS名称,我需要将字段的值放入数据库中。

但是首先,我需要一种方法,如何使用Visual Basic获取值,然后再查看如何将值放在db上。 所以这是告诉我需要的值的图像在XML的``,td''下。 但是表db的表应如下所示。...XML部分的值是第二个表中的第一个。

enter image description here

对于这部分代码,我可以使用

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

但是我有一个问题:

1-路径的差异和xe = XElement.Load

2-选择el Take 1).FirstOrDefault ...如何更改此参数以获取文档具有的所有值,而不仅仅是第一个。

3-如果我的xml有两个标题,我应该使用相同的sintax,因为实际上,正如您在照片中所看到的那样。 谢谢您的帮助@dbasnett

我所有的Xml在这里: enter link description here

2 个答案:

答案 0 :(得分:1)

XML示例的格式不正确。这可能会给你一个想法

使用生产代码

    Dim path As String = "put path to xml file here"
    Dim xe As XElement
    xe = XElement.Load(path) 'load the xml from file

因为这是VB,所以可以使用文字进行测试。我已尽力修复XML

    Dim xe As XElement

    xe = <title>TOSSICOLOGIA D'ABUSO
            <component>
                 <section>
                     <code code="31011" codeSystemName="Codifica Interna Laboratorio" displayName="Etanolo (urine)"></code>
                     <text>
                         <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>
                     </text>
                 </section>
             </component>
             <section>
                 <code code="32000" codeSystemName="Codifica Interna Laboratorio" displayName="Creatininuria"></code>
                 <text>
                     <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>
                 </text>
             </section>
         </title>

接下来找到其中一张表。我将使用代码节点执行此操作

    Dim sectn As XElement = (From el In xe...<code> Where el.@code = "32000" 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

看看下面的链接

LINQ to XML link

答案 1 :(得分:0)

解决方案

私人子GetContinents()

public partial class Form2 : Form
{       

    public Form2()
    {
        InitializeComponent();
        timer1.Start();            
    }

    [FlagsAttribute]
    public enum EXECUTION_STATE : uint
    {
        ES_AWAYMODE_REQUIRED = 0x00000040,
        ES_CONTINUOUS = 0x80000000,
        ES_DISPLAY_REQUIRED = 0x00000002,
        ES_SYSTEM_REQUIRED = 0x00000001
        // Legacy flag, should not be used.
        // ES_USER_PRESENT = 0x00000004
    }

    [DllImport("kernel32.dll", SetLastError = true)]
    static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags);

    private void timer1_Tick(object sender, EventArgs e)
    {
        SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS | EXECUTION_STATE.ES_SYSTEM_REQUIRED);            
    }
}