How do I read Element in specific XML file in C#? -


my file xml:

<document xmlns="http://www.abbyy.com/finereader_xml/finereader10-schema-v1.xml" version="1.0" producer="abbyy finereader engine 11" languages="" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://www.abbyy.com/finereader_xml/finereader10-schema-v1.xml http://www.abbyy.com/finereader_xml/finereader10-schema-v1.xml">  <page width="1006" height="636" resolution="300" originalcoords="1" rotation="rotatedupsidedown">   <block blocktype="text" blockname="" l="979" t="613" r="1006" b="636"><region><rect l="979" t="613" r="1006" b="636"/></region> <text> <par linespacing="890"> <line baseline="17" l="985" t="620" r="1006" b="636"><formatting lang="englishunitedstates"><charparams l="985" t="620" r="1006" b="636" suspicious="1">r</charparams></formatting></line></par> </text> </block>   <block blocktype="barcode" blockname="" l="242" t="21" r="772" b="116"><region><rect l="242" t="21" r="772" b="116"/></region> <text> <par><line baseline="0" l="0" t="0" r="0" b="0"><formatting lang="">049102580225180310</formatting></line></par> </text> <barcodeinfo type="interleaved25"/> </block>  </page> </document> 

i want extract number 049102580225180310 located in <formatting>..</formatting>

i try code:

xelement racine = xelement.load("test_xml.xml");  var query = xx in racine.elements(xname.get("block"))             select new             {                 codebar= xx.attribute(xname.get("formatting")).value             }; 

but haven't nothing

here's console program, gets 2nd formatting (where lang='') node.

using system; using system.xml;  namespace consoleapplication1 {     class program {         static void main(string[] args) {             xmldocument xml = new xmldocument();             xml.load("c:\\temp\\test.xml");              nametable nt = new nametable();             xmlnamespacemanager nsmgr;             nsmgr = new xmlnamespacemanager(nt);             nsmgr.addnamespace("html", xml.documentelement.namespaceuri);              xmlnode ndformat = xml.selectsinglenode("//html:formatting[@lang='']", nsmgr);             if (ndformat != null) {                 console.writeline(ndformat.innertext);             }          }     } } 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -