user2598157
user2598157

Reputation:

More child nodes of XML tag

I am parsing XML file. I am using DOM parser. I have 3 child nodes of tag Layer but i am getting 7 child nodes.All 4 child nodes are empty. How do i parse the child nodes if i am not getting correct number of child nodes.

My XML file code snippet is

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

Upvotes: 0

Views: 124

Answers (1)

Himanshu
Himanshu

Reputation: 2454

The seven children include 3 newlines and GATE POST. Filter based on the node type if you want 3 specific children. In python you'd do this :-

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

This gives :-

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

Upvotes: 1

Related Questions