使用dom cencepts读取xml [英] to read xml using dom cencepts

查看:84
本文介绍了使用dom cencepts读取xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在使用dom概念进行XML阅读,但我无法正确检索值。



我想要回到下面的部分



Hi,

Iam doing XML reading using dom concepts, But i couldn't retrieve values correctly.

I WANTTO RETRIEVE BELOW PART

<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>







这里是我想要的完整示例XML回顾使用循环。






HERE IS THE FULL SAMPLE XML WHERE I WANT TO RETRIEVE USING FOR 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>
   </article>
</articles>







我的代码是:






My code is:

Dim doc As New XmlDocument()
        Dim sValue, sPgName As String
        Dim sLeft, sTops, sRight, sBottom As String
        Dim ObjZoneInfo As CZoneInfo
        Try
            doc.Load(sFile)
              If doc.ChildNodes.Item(0).Name = "xml" Then
                If doc.ChildNodes.Item(1).Name = "articles" Then
                    For i As Integer = 0 To doc.ChildNodes.Item(1).ChildNodes.Count - 1
                        If doc.ChildNodes.Item(2).ChildNodes.Item(i).Name = "article" Then
                            ObjZoneInfo = New CZoneInfo
                            For j As Integer = 0 To 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" Then
                                    If sProFiles.Contains(sValue) = False Then
                                        sProFiles.Add(sValue)
                                    End If
                                    ObjZoneInfo.PageName = sValue : sPgName = sValue

推荐答案

你在做什么不是从xml中提取数据的正确方法。您应该使用XPath来提取信息。查看本文使用XPath和XmlDocument操作XML数据(C#) [ ^ ]。祝你好运
What are you doing is not the right way of extracting data from xml. You should be using XPath to extract information. Check this article Manipulate XML data with XPath and XmlDocument (C#)[^]. Good luck


这篇关于使用dom cencepts读取xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆