用jdom来解析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) 是 Web 上的数据通用语言。它使开发人员能够将结构化数据,从许多不同的应用程序传递到桌面,进行本地计算和演示。XML 允许为特定应用程序创建唯一的数据格式。它还是在服务器之间传输结构化数据的理想格式。
什么是 MSXML?
MSXML 是提供核心 XML 服务的 Microsoft 软 ......
1、arraycollection转化为xml,代码如下:
//动态生成树形结构
public static function flatArrayToXML(arr:Object,rootname:String=null,nodename:String=null, outputString:Boolean=false):Object{
if (arr is Array){
......
写一个XML文件 TinyXML 是一个mini的C++ XML解析库,它是非验证的,它可以很容易的集成到其他的程序中.它解析一份XML doc,以此创建一个可以被读、写,保存的DOM.它主要的类层次架构,函数原形详细说明参看: http://www.grinninglizard.com/tinyxml/index.html
// 以下以简单的程序TinyXMLTest为例 TinyXML中最根本的就是Docu ......
test.html
———————————————————————————————————————& ......
个人收集、整理了一些LINQ TO XML的基本方法,希望各位大虾多多指导:
/// <summary>
///Xml节点属性
/// </summary>
public class XmlAttribute
{
public XmlAttribute()
{
}
public XmlAttribute(string _key,object _value)
&nbs ......