c# - How to extract XML data -



c# - How to extract XML data -

i have xml file has next data,

<extcode type="abc" code="12345" />

i want able extract code, i.e., 12345, rows type abc. tried

xpathselectelements("type[@name='abc']")

but returned nothing.

thanks.

edit figured out problem namespace. xml file aw:extcode instead of extcode , caused query not work properly. how should in presence of namespace? when tried use

xmlnametable nametable = doc.nametable;

compiler complains can't resolve nametable.

personally i'd utilize linq xml, preferred way of working xml data. this:

xdocument doc = xdocument.load("test.xml"); int code = doc.descendants("extcode") .where(x => (string) x.attribute("type") == "abc") .first() .attribute("code");

one reason why xpath isn't working may attribute called "type" rather "name" though...

c# .net xml xpath

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -