【问题标题】:Extract Value from a XML Attribute with xpath/c#使用 xpath/c# 从 XML 属性中提取值
【发布时间】:2017-07-28 12:46:12
【问题描述】:

我目前正致力于在 SSIS 的脚本任务中使用 xpath 和 C# 从 XML 文件中提取数据。 我想稍后将此信息填充到 SQL 表中。

我的输入 Xml 文件如下所示

<Order>
<Header dateOfExecution="2017-06-22 08:30:09" orderId="5000206348" status="O" messageId="1" type="REQ" serviceProviderId="SP010" externalId1="b0ddcfece1a345338f20902401fa1e71" />
<Body>
    <Oli>
        <OliControl oliId="1" subscriptionId="990448" />
        <MIGOPT>
            <MigratedOptions>
                <Option operation="CHG" optionType="FLNDetails" optionId="O2O0056">
                    <Attribute name="fixedLineOption" value="2" />
                    <Attribute name="portingDate" value="2017-07-03 06:00:00" />
                    <Attribute name="portingWindow" value="06:00:00" />
                    <Attribute name="fixedLineSource" value="D001" />
                    <Attribute name="fixedLineType" value="Analog" />
                    <Attribute name="fixedLineNumber" value="490" />
                    <Attribute name="LAC" value="06736" />
                </Option>
            </MigratedOptions>
        </MIGOPT>
    </Oli>
</Body>
</Order>

我设法从标题中获取“类型”的值

 string  type = doc.SelectSingleNode("//Header/@type").InnerText;

但不知何故,当我试图从每个属性中获取值时,这些函数不起作用

 string portingDate = doc.SelectSingleNode("//Attribute[name='portingDate']/@value").InnerText;

我的错误在哪里?

【问题讨论】:

    标签: c# xml xpath ssis


    【解决方案1】:

    您在name 之前缺少@。改成这样:

    doc.SelectSingleNode("//Attribute[@name='portingDate']/@value");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-16
      • 2021-03-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多