2017-07-28 109 views
1

我目前正致力於在SSIS中的腳本任務中使用xpath和C#從XML文件提取數據。 我想稍後將此信息填充到SQL表中。使用xpath/c從XML屬性中提取值#

我的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; 

我的錯誤在哪裏?

回答

3

你錯過了@之前name。像這樣改變它:

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