c# - Having empty output for selected node in XML -


i have xml file includes nodes , children same name , attributes.

<?xml version="1.0"?> <purchaseorder purchaseordernumber="99503" orderdate="1999-10-20">   <address type="shipping">     <name>ellen adams</name>     <street>123 maple street</street>     <city>mill valley</city>     <state>ca</state>     <zip>10999</zip>     <country>usa</country>   </address>   <address type="billing">     <name>tai yee</name>     <street>8 oak avenue</street>     <city>old town</city>     <state>pa</state>     <zip>95819</zip>     <country>usa</country>     <address type="buying">         <name>ellen adams</name>     </address>     <address type="transporting">         <name>tai yee</name>         <street>8 oak avenue</street>     </address>   </address>   <deliverynotes>please leave packages in shed driveway.</deliverynotes>   <items>     <item partnumber="872-aa">       <productname>lawnmower</productname>       <quantity>1</quantity>       <usprice>148.95</usprice>       <comment>confirm electric</comment>     </item>     <item partnumber="926-aa">       <productname>baby monitor</productname>       <quantity>2</quantity>       <usprice>39.98</usprice>       <shipdate>1999-05-21</shipdate>     </item>   </items> </purchaseorder> 

i want have address nodes attributes output. problem there nested nodes have address node child. getting access child address problem. if again has child name address not want give me node have done in following code

public void find_node(string id_node)  {     xelement root = xelement.load("purchaseorder.xml");     ienumerable<xelement> address =         el in root.elements("address")         (string)el.attribute("type") == "buying"         select el;      foreach (xelement el in address)     {         var newelement = new xelement(                                 el.name.localname,                                 el.attributes(),                                 el.elements().where(o => o.name.localname != "address")                          );         console.writeline(newelement.tostring());     } } 

the desired output code be

<address type="buying">     <name>ellen adams</name> </address> 

but has empty output when running above function.

may ask have ride of empty output function?

if mean address elements regardless of location within xml, long matches attribute filter, can use descendants("address") instead :

ienumerable<xelement> address =                 el in root.descendants("address")                 (string)el.attribute("type") == "buying"                 select el; 

Comments

Popular posts from this blog

php - Webix Data Loading from Laravel Link -

libGdx unable to find files in android application data directory -

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -