易截截图软件、单文件、免安装、纯绿色、仅160KB

解析xml文件的几种常见的方法

xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<mobile-list>
<mobile type="Nokia2652">
<wap2>false</wap2>
<width>115</width>
</mobile>
<mobile type="Nokia2650">
<wap2>false</wap2>
<width>115</width>
</mobile>
<mobile type="Nokia6108">
<wap2>false</wap2>
<width>115</width>
</mobile>
</mobile-list>
-----------------------------------------------------
-----------------------------------------------------
使用jdom读xml文件:
package com.pk.xml;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
public class JDOMxml {
public static void main(String[] args) throws JDOMException, IOException {
try{
//获取解析器
SAXBuilder builder = new SAXBuilder();
//解析文件
File file = new File("D:\\项目\\me\\mobilelist.xml");
Document document = builder.build(file);
//取根节点
Element root = document.getRootElement();
//取的节点列表
List books = root.getChildren();
for(int i = 0 ; i<books.size();i++){
//取得某一个节点
Element book = (Element) books.get(i);
//获取属性值
String type = book.getAttributeValue("type");
System.out.print(type+"\t");

String text = book.getChild("wap2").getText();
String texts = book.getChild("width").getText();
System.out.print(text+"\t");
System.out.println(texts+"\t");
}
}catch (Exception e) {
e.printStackTrace();


相关文档:

XML解析方法讲解

XML现在已经成为一种通用的数据交换格式,它的平台无关性,语言无关性,系统无关性,给数据集成与交互带来了极大的方便。对于XML本身的语法知识与技术细节,需要阅读相关的技术文献,这里面包括的内容有DOM(Document Object Model),DTD(Document Type Definition),SAX(Simple API for XML),XSD(Xml Schema Definition),XSLT(Exten ......

XML第一课

HTML.html文件
<div align="center" class="style1">
  <p>冰棍列表</p>
  <p></p>
  <table width="400" border="1">
    <tr>
      <th scope="col"><font size="4">品牌</font></th> ......

XML第四课

book_schema.xml文件
<?xml version="1.0" encoding="gb2312"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
 <xs:element name="丛书">
  <xs:complexType>
   <xs:sequence>
    <xs:element name="书">
&n ......

flex xml遍历

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:XML id="xmlSource">
    <node label="grandFather" state="unchecked">
        <node label="Father" state="un ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号