用java实现xml文档的导入并显示出地图
来源:百度知道 编辑:UC知道 时间:2024/06/19 17:46:12
这是地图的一些信息
map units="mm">
attribute>
<key>name</key>
<value>"Example Map"</value>
</attribute>
- <area>
<point x="20" y="80" />
<point x="70" y="30" />
<point x="150" y="70" />
<point x="160" y="150" />
<point x="110" y="210" />
<point x="70" y="240" />
<point x="10" y="200" />
<point x="40" y="160" />
- <safe-edge>
<point x="20" y="80" />
<point x="70" y="30" />
</safe-edge>
- <zone state="clearing">
<point x="20&quo
import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
public class Xml {
public static void main(String[] args) {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(new File("D:\..\xml文件名.xml"));
Element rootElement = document.getDocumentElement();
NodeList list = rootElement.getElementsByTagName("Header");
Element element = (Element) list.item(0);
System.out.println(element.getChildNodes().item(0).getNodeValue());
} catch (Exception e) {
System.out.println("exception:" + e.getMessage());
}
}
}