vb.net - to read xml using dom cencepts -



vb.net - to read xml using dom cencepts -

iam doing xml reading using dom concepts, couldn't retrieve values correctly.

i want retrieve below part using loop statement

<area id="508" type="paragraph" visible="1" source_ap="true" invert="false" rotation="0" ignoretext="0"> <pagename><![cdata[11187_2014_06_14_000002_0004_nfhez]]></pagename> <pagenumber>1</pagenumber> <left>603</left> <top>868</top> <right>764</right> <bottom>1132</bottom> <polygon ispolygon="0" noofpoints="0"><![cdata[]]></polygon> </area>

here total sample xml want retrieve using loop.

<?xml version="1.0" encoding="utf-8"?> <articles> <template istemplate="true" twidth="0" theight="0" uwidth="0" uheight="0" ubottom="0"> </template> <article name="11187_2014_06_14_000002_0004_nfhez_00004" id="4"> <articlename><![cdata[11187_2014_06_14_000002_0004_nfhez_00004]]></articlename> <input_pages> <page name="11187_2014_06_14_000002_0004_nfhez" number="3"> <pagepdfheight>1125</pagepdfheight> <pagepdfwidth>786</pagepdfwidth> <pagejpgheight>1125</pagejpgheight> <pagejpgwidth>786</pagejpgwidth> <pagejpgresolution>72</pagejpgresolution> <name><![cdata[11187_2014_06_14_000002_0004_nfhez]]></name> <article_area>0</article_area> <article_percentage>0</article_percentage> </page> </input_pages> <noofpage>1</noofpage> <output_pages> <page number="1" height="0" width="0"/> </output_pages> <read> <area id="508" type="paragraph" visible="1" source_ap="true" invert="false" rotation="0" ignoretext="0"> <pagename><![cdata[11187_2014_06_14_000002_0004_nfhez]]></pagename> <pagenumber>1</pagenumber> <left>603</left> <top>868</top> <right>764</right> <bottom>1132</bottom> <polygon ispolygon="0" noofpoints="0"><![cdata[]]></polygon> </area> <area id="507" type="paragraph" visible="1" source_ap="true" invert="false" rotation="0" ignoretext="0"> <pagename><![cdata[11187_2014_06_14_000002_0004_nfhez]]></pagename> <pagenumber>1</pagenumber> <left>462</left> <top>868</top> <right>601</right> <bottom>1131</bottom> <polygon ispolygon="0" noofpoints="0"><![cdata[]]></polygon> </area> </read>

my code is:

dim doc new xmldocument() dim svalue, spgname string dim sleft, stops, sright, sbottom string dim objzoneinfo czoneinfo seek doc.load(sfile) if doc.childnodes.item(0).name = "xml" if doc.childnodes.item(1).name = "articles" integer = 0 doc.childnodes.item(1).childnodes.count - 1 if doc.childnodes.item(2).childnodes.item(i).name = "article" objzoneinfo = new czoneinfo j integer = 0 doc.childnodes.item(2).childnodes.item(i).childnodes.count - 1 svalue = doc.childnodes.item(1).childnodes.item(i).childnodes.item(j).innertext if doc.childnodes.item(1).childnodes.item(i).childnodes.item(j).name = "page_name" if sprofiles.contains(svalue) = false sprofiles.add(svalue) end if objzoneinfo.pagename = svalue : spgname = svalue

i understand searching nodes "area" tag, seek this:

dim tagareas xmlnodelist = doc.getelementsbytagname("area")

you can utilize each loop:

for each tagarea xmlelement in tagareas '______your code here. if wanted retrieve "area" tag don't understand code posted next

now, access attributes of area nodes, must utilize following:

dim area_id integer = integer.parse(tagarea.getattribute("id")) 'if want obtain id info integer dim area_type string = tagarea.getattribute("type") 'so etc___________________

if want access kid nodes:

dim area_pagenum integer = integer.parse(tagarea("pagenumber"))

vb.net

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -