vb.net - Object Not Found Parsing XML -


i have following xml being returned me:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>   <document xmlns="@link" xmlns:xsi="@link" xsi:schemalocation="@link" version="1.0">     <field left="0" top="0" right="100" bottom="20" type="text">       <value encoding="utf-16">11266</value>       <line left="8" top="4" right="55" bottom="17">         <char left="8" top="4" right="13" bottom="16" confidence="65" suspicious="true">1</char>         <char left="18" top="4" right="23" bottom="16" confidence="68" suspicious="true">1</char>         <char left="27" top="4" right="35" bottom="16" confidence="100">2</char><char left="36" top="4" right="45" bottom="17" confidence="100">6</char>         <char left="46" top="4" right="55" bottom="16" confidence="100">6</char>       </line>    </field> </document> 

i'm trying read value node. code looks this:

dim m_xmld = new xmldocument() m_xmld.load(xmlfile)  return m_xmld.selectsinglenode("/field/value").innertext 

what doing wrong? tried /document/field/value no avail :(

there 2 problems code. first, need specify xml namespace. xml document contains default namespace on document element (xmlns="@link"). means must explicitly specify namespace when reference element in document. xmldocument, need create xmlnamespacemanager , pass select methods. instance:

dim m_xmld new xmldocument() m_xmld.load(xmlfile) dim nsmgr new xmlnamespacemanager(m_xmld.nametable) nsmgr.addnamespace("x", "@link") return m_xmld.selectsinglenode("/x:document/x:field/x:value", nsmgr).innertext 

or, if don't want hard-code namespace uri, can grab loaded document, this:

nsmgr.addnamespace("x", m_xmld.documentelement.namespaceuri) 

the second problem trying select /field/value rather /document/field/value. when selecting xmldocument object, itself, selection begins root of document ("above" document element).


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -