EDN Admin
Well-known member
Hello,
Can somebody show me some sample code on extracting the data out of the below xml? I am new at xml and having trouble getting the data out of each <Person> element and it attributes. I manage to query the <Person> element but dont know
how to access its data..
IEnumerable<XElement> personReport = Global.GlobalVariables.XmlRespond.XElementRespond.Descendants("Person");<br/>
<br/>
foreach (XElement myRpt in personReport )<br/>
{ <br/>
<span style="white-spacere //not sure how to loop through each child and sub-child and it attributes to get the data.<br/>
}
<?xml version="1.0" encoding="utf-8" ?> <br/>
<MYXML xmlns="http://www.fix.org/MYXML-5-0-SP2 <br/>
<Batch><br/>
<Person xmlns:ns2="http://www.fix.org/MYXML-5-0-SP2" xmlns="" CopyMsgInd="Y" TxnTm="2012-01-03T14:00:00-06:00" ><br/>
<ns2:Hdr TID="EServices, L." SID="NOCC" /> <br/>
<ns2:Instrmt UOM="MWh" MatDt="2011-12-29T00:00:00-06:00" CFI="FOR" ID="EDNH1.F.X" Sym="HH Hour Ending (Daily) <br/>
<ns2:Evnt Dt="2012-01-04T00:00:00-06:00" EventTyp="13" /> <br/>
<ns2:Evnt Dt="2012-01-04T00:00:00-06:00" EventTyp="14" /> <br/>
<ns2:Evnt Txt="SSH" Px="1200" EventTyp="100" /> <br/>
<ns2:Evnt Txt="SSH" Px="2200" EventTyp="101" /> <br/>
</ns2:Instrmt><br/>
<ns2:RptSide InptSrc="E" Side="1 <br/>
<ns2ty R="12" ID="EMatch" /> <br/>
<ns2ty R="1" ID="Services, L." /> <br/>
<ns2ty R="4" ID="Ronnie" /> <br/>
</ns2:RptSide><br/>
</Person><br/>
<Person xmlns:ns2="http://www.fix.org/MYXML-5-0-SP2" xmlns="" CopyMsgInd="Y" TxnTm="2012-02-03T14:00:00-06:00" ><br/>
<ns2:Hdr TID="EServices, L." SID="NOCC" /> <br/>
<ns2:Instrmt UOM="MWh" MatDt="2011-12-29T00:00:00-06:00" CFI="FOR" ID="EDNH1.F.X" Sym="HH Hour Ending (Daily) <br/>
<ns2:Evnt Dt="2012-02-04T00:00:00-06:00" EventTyp="13" /> <br/>
<ns2:Evnt Dt="2012-02-04T00:00:00-06:00" EventTyp="14" /> <br/>
<ns2:Evnt Txt="SSH" Px="1300" EventTyp="100" /> <br/>
<ns2:Evnt Txt="SSH" Px="2300" EventTyp="101" /> <br/>
</ns2:Instrmt><br/>
<ns2:RptSide InptSrc="E" Side="1 <br/>
<ns2ty R="12" ID="EMatch" /> <br/>
<ns2ty R="1" ID="Services, L." /> <br/>
<ns2ty R="4" ID="Jonnie" /> <br/>
</ns2:RptSide><br/>
</Person><br/>
</Batch><br/>
</MYXML>
View the full article
Can somebody show me some sample code on extracting the data out of the below xml? I am new at xml and having trouble getting the data out of each <Person> element and it attributes. I manage to query the <Person> element but dont know
how to access its data..
IEnumerable<XElement> personReport = Global.GlobalVariables.XmlRespond.XElementRespond.Descendants("Person");<br/>
<br/>
foreach (XElement myRpt in personReport )<br/>
{ <br/>
<span style="white-spacere //not sure how to loop through each child and sub-child and it attributes to get the data.<br/>
}
<?xml version="1.0" encoding="utf-8" ?> <br/>
<MYXML xmlns="http://www.fix.org/MYXML-5-0-SP2 <br/>
<Batch><br/>
<Person xmlns:ns2="http://www.fix.org/MYXML-5-0-SP2" xmlns="" CopyMsgInd="Y" TxnTm="2012-01-03T14:00:00-06:00" ><br/>
<ns2:Hdr TID="EServices, L." SID="NOCC" /> <br/>
<ns2:Instrmt UOM="MWh" MatDt="2011-12-29T00:00:00-06:00" CFI="FOR" ID="EDNH1.F.X" Sym="HH Hour Ending (Daily) <br/>
<ns2:Evnt Dt="2012-01-04T00:00:00-06:00" EventTyp="13" /> <br/>
<ns2:Evnt Dt="2012-01-04T00:00:00-06:00" EventTyp="14" /> <br/>
<ns2:Evnt Txt="SSH" Px="1200" EventTyp="100" /> <br/>
<ns2:Evnt Txt="SSH" Px="2200" EventTyp="101" /> <br/>
</ns2:Instrmt><br/>
<ns2:RptSide InptSrc="E" Side="1 <br/>
<ns2ty R="12" ID="EMatch" /> <br/>
<ns2ty R="1" ID="Services, L." /> <br/>
<ns2ty R="4" ID="Ronnie" /> <br/>
</ns2:RptSide><br/>
</Person><br/>
<Person xmlns:ns2="http://www.fix.org/MYXML-5-0-SP2" xmlns="" CopyMsgInd="Y" TxnTm="2012-02-03T14:00:00-06:00" ><br/>
<ns2:Hdr TID="EServices, L." SID="NOCC" /> <br/>
<ns2:Instrmt UOM="MWh" MatDt="2011-12-29T00:00:00-06:00" CFI="FOR" ID="EDNH1.F.X" Sym="HH Hour Ending (Daily) <br/>
<ns2:Evnt Dt="2012-02-04T00:00:00-06:00" EventTyp="13" /> <br/>
<ns2:Evnt Dt="2012-02-04T00:00:00-06:00" EventTyp="14" /> <br/>
<ns2:Evnt Txt="SSH" Px="1300" EventTyp="100" /> <br/>
<ns2:Evnt Txt="SSH" Px="2300" EventTyp="101" /> <br/>
</ns2:Instrmt><br/>
<ns2:RptSide InptSrc="E" Side="1 <br/>
<ns2ty R="12" ID="EMatch" /> <br/>
<ns2ty R="1" ID="Services, L." /> <br/>
<ns2ty R="4" ID="Jonnie" /> <br/>
</ns2:RptSide><br/>
</Person><br/>
</Batch><br/>
</MYXML>
View the full article