Linq to XML - Problem selecting elements -


<invoice type='component' displayname='invoice' pluralname='invoices' msgversion='1' version='1'>   <userdata type='specialelement'>     <something />   </userdata>   <from type='specialelement'>     <something />   </from>   <to type='specialelement'>     <something />   </to>   <cdtdbtnoteamt type='xsd:decimal' />   <pmtduedt type='xsd:date' />   <adjstmnt>     <adjamt />     <rate />   </adjstmnt>   <cpydplct type='picklist'>     <item text='copy duplicate' value='codu' />     <item text='copy' value='copy' />     <item text='duplicate' value='dupl' />   </cpydplct>   <invitems type='parentelement'>     <invgd type='element'>       <gddesc type='xsd:decimal' />       <qtyvl type='xsd:decimal' />       <chrgamt type='xsd:decimal' />       <prcevl type='xsd:decimal' />     </invgd>   </invitems> </invoice> 

hi,

i need elements

  • the type attribute not specialelement or picklist
  • there child elements
  • the type attribute of parent not parentelement

so, based on xml snippet want adjstmnet , invgd elements.

the closest can is

var query = n in xe.elements()         let attributetype = n.attribute("type").value         attributetype != "specialelement"         attributetype != "picklist"         n.haselements         select n; 

but doesn't include invgd element.

any ideas on need change/add?

thanks,

david

using xe.descendants() instead of xe.elements() should help. of course need add check parent element.

var query = el in xe.descendants()             let atttype = (string)el.attribute("type")             let parenttype = (string).el.parent.attribute("type")             atttype != "specialelement" && atttype != "picklist"                   && el.haselements                   && parenttype != "parentelement"             select el 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -