解析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 version="1.0" encoding="GB2312"?>
<RESULT>
<VALUE>
<NO>A1234</NO>
<ADDR>四川省XX县XX镇XX路X段XX号</ADDR>
</VALUE>
<VALUE>
<NO>B1234</NO>
<ADDR>四川省XX市XX乡XX村XX组</ADDR>
</VALUE>
</RESULT>
1)DOM
& ......
最近在项目中遇到flex跨域访问的安全沙箱问题,查资料了解到需要在服务端加上crossdomain.xml文件,即:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-do ......
声明
/// <summary>
/// XML文档
/// </summary>
XmlDocument xmldoc;
&n ......
个人收集、整理了一些LINQ TO XML的基本方法,希望各位大虾多多指导:
/// <summary>
///Xml节点属性
/// </summary>
public class XmlAttribute
{
public XmlAttribute()
{
}
public XmlAttribute(string _key,object _value)
&nbs ......