繁体   English   中英

XML标签的更多子节点

[英]More child nodes of XML tag

我正在解析XML文件。 我正在使用DOM解析器。 我有3个标记为Layer的子节点,但我有7个子节点。所有4个子节点均为空。 如果我没有正确数量的子节点,我该如何解析子节点。

我的XML文件代码段是

<Layer Description="" MinZoom="1" MaxZoom="1000000000" Visible="3" RemotHostType="LocalFile" RemotHost="" FolderName="GATE POST" Path="" LayerStatus="ReadWrite">
            <ParamList>
                <DrawingParam LineColor="-11179217" FillColor="-16751616" SelectedLineColor="-16744448" LineType="0" LineWidth="1" IconType="0" Options="0" ZoomLimit="9E+99" LayerType="1" />
                <DrawingParam LineColor="1" FillColor="1" SelectedLineColor="1" LineType="1" LineWidth="1" IconType="1" Options="1" ZoomLimit="1" LayerType="1" />
            </ParamList>
            <TextParamList>
                <TextParam FieldIndex="-1" FontName="Arial" Bold="0" Italic="0" StrikeOut="0" TextAngle="0" TextColor="-16777216" TextFontSize="12" TextPosition="1" Underline="0" MinZoom="1" MaxZoom="1000000000" ShowText="False" FontFector="100000" />
            </TextParamList>
            <Regions>
                <Region ID="0" FileName="GATE POST.ogl" FilePath="" FileType="OGL" RemotHost="" RemotHostType="LocalFile" />
            </Regions>GATE POST</Layer>

这七个孩子包括3个换行符和GATE POST。 如果需要3个特定的子代,则根据节点类型进行过滤。 在python中,您可以这样做:

   from xml.dom.minidom import parseString
   for child in dom.documentElement.childNodes:
      if child.nodeType == child.ELEMENT_NODE:
         print child

这给出了:-

$ python test.py
<DOM Element: ParamList at 0x10c124a28>
<DOM Element: TextParamList at 0x10bfb0ab8>
<DOM Element: Regions at 0x10bfb98c0>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM