我已经读取了字符串中的所有xml内容。现在我正在解析那个字符串。 我解析ias的代码如下:
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);
有一个标签名称区域,我的xml字符串中有很多区域。但我面临的问题是这个xmlDoc.getelementBytagName只返回1个元素。
我的xml字符串的片段如下:
<?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>
答案 0 :(得分:1)
<强> 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);