xml - How to run foreach elemnt in XMLDocument c# -
can please tell me how run foreach
cycle goes through every element person
i have code loading doc1
not filled data
xdocument doc = xdocument.load(path); foreach (var doc1 in doc.descendants("person"))
the xml looks this
<report xmlns="http://askmk/ask/report"> <reporttypeid>5</reporttypeid> <bankid>111</bankid> <referenceno>1</referenceno> <referencenoreporter /> <datecreated>2017-01-31t01:50:44.0000000+01:00</datecreated> <datafromdate>2017-01-27t12:00:00.0000000+01:00</datafromdate> <datatodate>2017-01-27t12:00:00.0000000+01:00</datatodate> <personlist> <person xmlns="http://askmk/ask/reporttypes"> <personobjectid>111</personobjectid> <cellphoneno>111 </cellphoneno> <dateofbirth>1985-03-18</dateofbirth> <email /> <embg>111111</embg> <isresident>1</isresident> <firstname>xxx</firstname> <gendertypeid>3</gendertypeid> <lastname>xxx</lastname> <phoneno /> <placeofbirth /> <iddocumentlist> <iddocument> <iddocumenttypeid>1</iddocumenttypeid> <placeofissue>. </placeofissue> <idno>1111</idno> </iddocument> </iddocumentlist> </person> <person xmlns="http://askmk/ask/reporttypes"> <personobjectid>1111</personobjectid> <cellphoneno>11111 </cellphoneno> <dateofbirth>1969-03-28</dateofbirth> <email /> <embg>1111</embg> <isresident>1</isresident> <firstname>xxx</firstname> <gendertypeid>3</gendertypeid> <lastname>xxx</lastname> <phoneno /> <placeofbirth /> <iddocumentlist> <iddocument> <iddocumenttypeid>2</iddocumenttypeid> <placeofissue>xxxx </placeofissue> <idno>1111</idno> </iddocument> </iddocumentlist> </person> </personlist> </report>
i know simple new c# , thats why asking.
the problem forgot namespace:
xdocument doc = xdocument.load(path); xnamespace ns = "http://askmk/ask/reporttypes"; foreach (var doc1 in doc.descendants(ns + "person")) { //todo }
for more can have at:
as @alexander pointed out +
xnamespace.addition
operator.
Comments
Post a Comment