top
Loading...
通過XMLObject操縱XML的例子
通過XML Object操縱XML的例子

[DDZ] 于 99-11-2 下午 03:25:41 加貼在 XML學習:

JavaScript(部分) 如下:
xmlDoc = new ActiveXObject( "Microsoft.XMLDOM" );
xmlDoc.async = false;
xmlDoc.load("Gis.xml");

//Set root to the XML document's root element, COLLECTION:
root = xmlDoc.documentElement;
//Walk from the root to each of its child nodes:
for( j=0; j<root.childNodes.length; j++ ){
child = root.childNodes.item(j);
if(child.nodeType != 8){ //is not comment
if(child.nodeName == "Boundary"){
for( i=0; i<child.attributes.length; i++ ){
attr = child.attributes.item(i);
if( attr.nodeName == "northbc" )
y1 = attr.nodeValue.valueOf();
else if( attr.nodeName == "westbc" )
x0 = attr.nodeValue.valueOf();
else if( attr.nodeName == "southbc" )
y0 = attr.nodeValue.valueOf();
else if( attr.nodeName == "eastbc" )
x1 = attr.nodeValue.valueOf();
}
}
else if( child.nodeName == "Feature" ){
for( i=0; i<child.attributes.length; i++ ){
attr = child.attributes.item(i);
if( attr.nodeName == "fid" )
id = attr.nodeValue.valueOf();
else if( attr.nodeName == "theme" )
theme = attr.nodeValue;
}
for( i=0; i<child.childNodes.length; i++ ){
obj = child.childNodes.item(i);
if( obj.nodeName == "Point" ){
setPoint( obj, id, theme );
}else if( obj.nodeName == "LineString" ){
setLineString( obj, id, theme );
}else if( obj.nodeName == "Polygon" ){
setPolygon( obj, id, theme );
}else if( obj.nodeName == "TextLabel" ){
setText( obj, id, theme );
}
}
}

XML如下(部分):
<!-- Boundary -->
<Boundary
northbc="16800000"
westbc="14800000"
southbc="16200000"
eastbc="15600000" />

<!-- Point Feature -->
<Feature fid="1" theme="揹拰">
<Point>
<Coordinate>15050000, 16450000</Coordinate>
</Point>
</Feature>
<!-- LineString with LineStyle -->
<Feature fid="8" theme="摴楬">
<LineString>
<LineStyle lcolor="YELLOW" lwidth="10" lstyle="DashDot" />
<Coordinate>15200000, 16500000</Coordinate>
<Coordinate>15200000, 16200000</Coordinate>
</LineString>
</Feature>
<!-- Polygon with EdgeProp (invisible edge) -->
<Feature fid="11" theme="摴楬">
<Polygon>
<EdgeProp serial="2" visible="FALSE" />
<EdgeProp serial="4" visible="FALSE" />
<Coordinate>15200000, 16500000</Coordinate>
<Coordinate>15550000, 16500000</Coordinate>
<Coordinate>15550000, 16600000</Coordinate>
<Coordinate>15200000, 16600000</Coordinate>
</Polygon>
</Feature>