-9

我有一个奇怪的 xml 文件,我想阅读 c#,我在互联网上搜索了很多,但没有找到适合我的案例

<XMLFile>
<Template>
<TestElement ID="22">
    <PlugIn Name="ESA620" TestID="1240"/>
    <Info>
        <Type>Current 1</Type>
        <Parameter>Current 1</Parameter>
        <Name>Current 1</Name>
    </Info>
    <ExpectedResult>
        <Standard AlphaName="IEC" CompleteName="IEC 60601" Type="Predefined">
            <Limit Key="::ST">
                <Unit>uA</Unit>
                <Value Type="High">100</Value>
            </Limit>
        </Standard>
    </ExpectedResult>
</TestElement>
.   .   .   .   .   .
<TestElement ID="35">
    <PlugIn Name="ESA620" TestID="1500"/>
    <Info>
        <Type>Current auxiliary</Type>
        <Name>Current auxiliary</Name>
    </Info>
    <ExpectedResult>
        <Standard AlphaName="IEC" CompleteName="IEC 60601">
            <Limit Key="::B">
                <Unit>uA</Unit>
            </Limit>
            <Limit Key="::BF">
                <Unit>uA</Unit>
            </Limit>
            <Limit Key="::CF">
                <Unit>uA</Unit>
            </Limit>
            <Limit Key="::B_DC">
                <Unit>uA</Unit>
            </Limit>
            <Limit Key="::BF_DC">
                <Unit>uA</Unit>
            </Limit>
            <Limit Key="::CF_DC">
                <Unit>uA</Unit>
            </Limit>
        </Standard>
    </ExpectedResult>
    <PlugInData PlugIn="ESA620">
        <ValueFilter>None</ValueFilter>
        <EnableBtn Skip="True" NA="True" Step="True"/>
        <ModuleOptions Sep="False" Exp="False" Stop="False"/>
        <TestOptions>
            <Run Opt="False" HaltOnFail="True" MultiPE="False" TotalLeakage="False" MeasType="0" TestVoltage="0" AppliedParts="0"/>
            <StopOnPC Before="False" After="False"/>
            <Delay On="2" Off="0"/>
        </TestOptions>
    </PlugInData>
    <TestElement ID="36">
        <PlugIn Name="ESA620" TestID="1510"/>
            <Info>
                <Type>Patient Current auxiliary </Type>
                <Parameter>Normal Condition</Parameter>
                <Name>Normal Condition</Name>
            </Info>
            <ExpectedResult>
            <Standard AlphaName="IEC" CompleteName="IEC 60601" Type="Predefined">
                <Limit Key="::B">
                    <Unit>uA</Unit>
                    <Value Type="High">100</Value>
                </Limit>
                <Limit Key="::BF">
                    <Unit>uA</Unit>
                    <Value Type="High">100</Value>
                </Limit>
                <Limit Key="::CF">
                    <Unit>uA</Unit>
                    <Value Type="High">10</Value>
                </Limit>
                <Limit Key="::B_DC">
                    <Unit>uA</Unit>
                    <Value Type="High">10</Value>
                </Limit>
                <Limit Key="::BF_DC">
                    <Unit>uA</Unit>
                    <Value Type="High">10</Value>
                </Limit>
                <Limit Key="::CF_DC">
                    <Unit>uA</Unit>
                    <Value Type="High">10</Value>
                </Limit>
            </Standard>
        </ExpectedResult>
    </TestElement>
    <TestElement ID="37">
        <PlugIn Name="ESA620" TestID="1520"/>
        <Info>
            <Type>Patient Current auxiliary</Type>
            <Parameter>Neutral open</Parameter>
            <Name>Neutral open</Name>
        </Info>
        <ExpectedResult>
            <Standard AlphaName="IEC" CompleteName="IEC 60601" Type="Predefined">
                <Limit Key="::B">
                    <Unit>uA</Unit>
                    <Value Type="High">500</Value>
                </Limit>
                <Limit Key="::BF">
                    <Unit>uA</Unit>
                    <Value Type="High">500</Value>
                </Limit>
                <Limit Key="::CF">
                    <Unit>uA</Unit>
                    <Value Type="High">50</Value>
                </Limit>
                <Limit Key="::B_DC">
                    <Unit>uA</Unit>
                    <Value Type="High">50</Value>
                </Limit>
                <Limit Key="::BF_DC">
                    <Unit>uA</Unit>
                    <Value Type="High">50</Value>
                </Limit>
                <Limit Key="::CF_DC">
                    <Unit>uA</Unit>
                    <Value Type="High">50</Value>
                </Limit>
            </Standard>
        </ExpectedResult>
    </TestElement>
    <TestElement ID="38">
.   .   .   .   .
    </TestElement>
</TestElement>
</Template>
<Result>
<ResultItem MTI="1" ElementID="22">
    <Status>Passed</Status>
    <Measurement Key="::ST">
        <Description>normal conditions, reverse polarity</Description>
        <Value Type="Float">.2</Value>
        <Unit>uA</Unit>
        <Status>Passed</Status>
    </Measurement>
</ResultItem>
.   .   .   .   .   
<ResultItem ElementID="35">
    <Status>Passed</Status>
    <ResultItem MTI="1" ElementID="36">
        <Status>Passed</Status>
        <Measurement Key="::1::B">
            <Description>patient circuit</Description>
            <Value Type="Float">.1</Value>
            <Unit>uA</Unit>
            <Status>Passed</Status>
        </Measurement>
        <Measurement Key="::2::CF">
            <Description>ECG</Description>
            <Value Type="Float">.1</Value>
            <Unit>uA</Unit>
            <Status>Passed</Status>
        </Measurement>
        <Measurement Key="::3::B">
            <Description>Spo2</Description>
            <Value Type="Float">.1</Value>
            <Unit>uA</Unit>
            <Status>Passed</Status>
        </Measurement>
        <Measurement Key="::4::B">
            <Description>NiBp</Description>
            <Value Type="Float">.1</Value>
            <Unit>uA</Unit>
            <Status>Passed</Status>
        </Measurement>
    </ResultItem>
    <ResultItem MTI="1" ElementID="37">
        <Status>Passed</Status>
        <Measurement Key="::1::B">
            <Description>Patient circuit</Description>
            <Value Type="Float">.1</Value>
            <Unit>uA</Unit>
            <Status>Passed</Status>
        </Measurement>
        <Measurement Key="::2::CF">
            <Description>ECG</Description>
            <Value Type="Float">.1</Value>
            <Unit>uA</Unit>
            <Status>Passed</Status>
        </Measurement>
        <Measurement Key="::3::B">
            <Description>Spo2</Description>
            <Value Type="Float">.1</Value>
            <Unit>uA</Unit>
            <Status>Passed</Status>
        </Measurement>
        <Measurement Key="::4::B">
            <Description>NiBp</Description>
            <Value Type="Float">.1</Value>
            <Unit>uA</Unit>
            <Status>Passed</Status>
        </Measurement>
    </ResultItem>
<ResultItem MTI="1" ElementID="38">
.   .   .   .   .   .
</ResultItem>
</ResultItem>
</Result>
</XMLFile>

我的 xml 文件由两部分组成,第一部分是模板,第二部分是值。我试图得到的例如:

电流 1:电流 1,单位:uA,上限:100,值:.2,状态通过

电流辅助:电流辅助:患者电流辅助:患者电路:单位:uA,上限:100,值:.1 状态:通过

ECG:单位:uA,上限:10,值:0.1 状态:通过

Spo2:单位:uA,上限:100,值:0.1 状态:通过

NiBp:单位:uA,上限:100,值:0.1 状态:通过

中性开路:患者电流辅助:患者电路:单位:uA,上限:500,值:0.1 状态:通过

ECG:单位:uA,上限:50,值:.1 状态:通过

Spo2:单位:uA,上限:500,值:0.1 状态:通过

NiBp:单位:uA,上限:500,值:0.1 状态:通过

如何用 c# 读取这个 xml?

4

1 回答 1

1

XDocument.Load

XDocument.Parse

string str =
@"<?xml version=""1.0""?>
<!-- comment at the root level -->
<Root>
    <Child>Content</Child>
</Root>";
XDocument doc = XDocument.Parse(str);
Console.WriteLine(doc);
于 2013-04-02T11:26:44.613 回答