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

用dom来解析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>

用DOM来解析类:
package com.pk.xml;
import java.io.File;
import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
public class DOMxml {
public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException {
//获取dom工厂
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
//获取dom解析器
DocumentBuilder builder = factory.newDocumentBuilder();
//解析的文件
File file = new File("D:\\项目\\me\\mobilelist.xml");
Document document = builder.parse(file);
//获取根节点
Element root = document.getDocumentElement();
//获取子节点列表
NodeList books = root.getChildNodes();
for(int i= 0 ; i<books.getLength();i++){
//获取每一个子节点
Node book = books.item(i);

if(book.getNodeType()==Node.ELEMENT_NODE){
//获取属性的值
String type = book.getAttributes().getNamedItem("type").getNodeValue();
System.out.print(type+"\t");
//循环子节点
for(Node node=book.getFirstChild();node!=null;node=node.getNextSibling()){
if(node.getNodeType()==Node.ELEMENT_NODE){

if(node.getNodeName().equals("wap2")){
String wap2 = node.getFirstChild


相关文档:

关于flex的crossdomain.xml文件存放目录

       最近在项目中遇到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 ......

xml/properties文件的相互保存转化

/*
练习使用java.util.properties类包来操作propertes及XML文件,通过store方法的调用可实现xml/properties文件的相互保存转化
*/
import java.util.*;
import java.io.*;
public class TestPropertes
{
public static void main(String[] args) {
   Properties pp = new Properties();
   Fi ......

TinyXML(C++ XML解析库)

写一个XML文件 TinyXML 是一个mini的C++ XML解析库,它是非验证的,它可以很容易的集成到其他的程序中.它解析一份XML doc,以此创建一个可以被读、写,保存的DOM.它主要的类层次架构,函数原形详细说明参看: http://www.grinninglizard.com/tinyxml/index.html
// 以下以简单的程序TinyXMLTest为例 TinyXML中最根本的就是Docu ......

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 ......

LINQ TO XML Common Class

个人收集、整理了一些LINQ TO XML的基本方法,希望各位大虾多多指导:
 /// <summary>
///Xml节点属性
/// </summary>
public class XmlAttribute
{
 public XmlAttribute()
 {
  
 }
    public XmlAttribute(string _key,object _value)
 &nbs ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号