Reputation: 125
i am currently working on extracting data from a XML file with xpath and C# in a script task in SSIS. I want to fill this infomation into a SQL table later.
My Input Xml-file looks like this
<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>
i manage to get the value of "type" from the header with
string type = doc.SelectSingleNode("//Header/@type").InnerText;
but somehow the functions doesn't work when i am trying to get the values from every Attribute
string portingDate = doc.SelectSingleNode("//Attribute[name='portingDate']/@value").InnerText;
where is my mistake?
Upvotes: 1
Views: 700
Reputation: 7095
You're missing @
before name
. Change it like this:
doc.SelectSingleNode("//Attribute[@name='portingDate']/@value");
Upvotes: 3