Muneem Habib
Muneem Habib

Reputation: 1094

xml.getelement by tag name is not working properly

I have read all xml content in a string. now i am parsing that string. My code for parsing ias as follows:

  parser=new DOMParser();
      xmlDoc=parser.parseFromString(output,"text/xml");//output is a string which contains xml

      var region= xmlDoc.getElementsByTagName("Region");
       console.log("Region lenght"+region.length);

There is a tag name Regions and there are alot of regions in my xml string. but issue i am facing is this xmlDoc.getelementBytagName is only returning 1 element.

Snippet of my xml string is as follows:

<?xml version="1.0"?>
<!--OfflineHtm [version 1.1.0]-->
<!--(C) Copyrights 2008-2015 ID Technologies Canada-->
<Project>
  <ProjectInformation>
    <FileHeader>IDGIS_PROJECT</FileHeader>
    <Details ProjectID="0" ProjectName="" Description="" StartDate="01/01/0001 00:00:00 AM" OwnerShip="" LastModified="01/01/0001 00:00:00 AM" Datum="WGS_84" Projection="DEFAULT" NoSignificantDecimals="8" ZoomCurrent="224" RasterHeight="0" Background="-1">Project Details</Details>
    <ProjectBounds XMin="25.9527142400271" YMin="44.3228898448188" XMax="26.2404541400271" YMax="44.5703763448188" ExtentBounds="yes">Bounds</ProjectBounds>
  </ProjectInformation>
  <Layers>
    <Layer ID="20" Description="" MinZoom="1" MaxZoom="1000000000" Visible="1" RemotHostType="LocalFile" RemotHost="" FolderName="Reference" Path="" LayerStatus="ReadWrite">
      <ParamList>
        <DrawingParam LineColor="-4925225" FillColor="-16760448" SelectedLineColor="-3657166" LineType="0" LineWidth="1" IconType="0" Options="3" ZoomLimit="9E+99" 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="1000" />
      </TextParamList>
      <Regions>
        <Region ID="0" FileName="Reference.rgn" FilePath="" FileType="IDGIS_ASCII" RemotHost="" RemotHostType="LocalFile" />
      </Regions>Reference</Layer>
    <Layer ID="19" Description="" MinZoom="1" MaxZoom="1000000000" Visible="1" RemotHostType="LocalFile" RemotHost="" FolderName="Water Valve" Path="" LayerStatus="ReadWrite">
      <ParamList>
        <DrawingParam LineColor="-4925225" FillColor="-16760448" SelectedLineColor="-3657166" LineType="0" LineWidth="1" IconType="0" Options="3" ZoomLimit="9E+99" 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="1000" />
      </TextParamList>
      <Regions>
        <Region ID="0" FileName="Water Valve.rgn" FilePath="" FileType="IDGIS_ASCII" RemotHost="" RemotHostType="LocalFile" />
      </Regions>Water Valve</Layer>

Upvotes: 0

Views: 161

Answers (1)

Ani
Ani

Reputation: 4523

JS

  parser=new DOMParser();
  xmlDoc=parser.parseFromString(output,"text/xml");//output is a string which contains xml

  var region= xmlDoc.getElementsByTagName("Regions"); // Regions
   console.log("Region length"+region.length);

Upvotes: 1

Related Questions