LINQ to XML: Getting child values of elements -


well, 1 xml file

  <?xml version="1.0" encoding="utf-8"?> <config>   <setup>     <test>10</test>     <copy>       <descr>aa</descr>       <descr>bb</descr>     </copy>   </setup> </config> 

and 1 linq query :(

dim query = q in xelement.load("\myxml.xml").elements("setup") _             q.element("test").value = "somevalue" _             select new {.test = q.element("test").value, _                              .copydescr = q.element("copy/descr").value} 

unfortunately, one, produces following straight-forward error.

the '/' character, hexadecimal value 0x2f, cannot included in name. 

so question is, how can child values contained in <description> too, without getting error? see love load values contained in copydescr list of(string) later usage...

thanks in advance!

you can use xpath:

q.xpathselectelements("copy/descr") 

however return list of elements. probable need join them somehow, code going be:

.copydescr = string.join( "," ,    qq in q.xpathselectelements("copy/descr") select qq.value ); 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -