`

xml 解释

阅读更多

1。xml 文件内容

 

<?xml version="1.0" encoding="UTF-8"?>
<modules>
    <module id="22222" title="11111" name="11111111" detail="11111111111111" actions="1111">
        <resource id="" title="" name="" detail="" actions="" />
        <resource id="" title="" name="" detail="" actions="" />
        <resource id="" title="" name="" detail="" actions="" />
        <resource id="" title="" name="" detail="" actions="" />
        <resource id="" title="" name="" detail="" actions="" />
        <resource id="" title="" name="" detail="" actions="">
            <resource id="" title="" name="" detail="" actions="" />
            <resource id="" title="" name="" detail="" actions="" />
            <resource id="" title="" name="" detail="" actions="">
                <resource id="" title="" name="" detail="" actions="" />
                <resource id="" title="" name="" detail="" actions="" >
                    <resource id="" title="" name="" detail="" actions="" ></resource>
                    <resource id="" title="" name="" detail="" actions="" ></resource>
                </resource>
                <resource id="" title="" name="" detail="" actions="" />
            </resource>
            <resource id="" title="" name="" detail="" actions="" />
            <resource id="" title="" name="" detail="" actions="" />
        </resource>
    </module>
    <module id="" title="" name="" detail="" actions="">
        <resource id="" title="" name="" detail="" actions="" />
        <resource id="" title="" name="" detail="" actions="" />
        <resource id="" title="" name="" detail="" actions="" />
        <resource id="" title="" name="" detail="" actions="" />
        <resource id="" title="" name="" detail="" actions="" />
        <resource id="" title="" name="" detail="" actions="">
            <resource id="" title="" name="" detail="" actions="" />
            <resource id="" title="" name="" detail="" actions="" />
            <resource id="" title="" name="" detail="" actions="">
                <resource id="" title="" name="" detail="" actions="" />
                <resource id="" title="" name="" detail="" actions="" >
                    <resource id="" title="" name="" detail="" actions="" ></resource>
                    <resource id="" title="" name="" detail="" actions="" ></resource>
                </resource>
                <resource id="" title="" name="" detail="" actions="" />
            </resource>
            <resource id="" title="" name="" detail="" actions="" />
            <resource id="" title="" name="" detail="" actions="" />
        </resource>
    </module>
    <module id="" title="" name="" detail="" actions="">
        <resource id="" title="" name="" detail="" actions="" />
        <resource id="" title="" name="" detail="" actions="" />
        <resource id="" title="" name="" detail="" actions="" />
        <resource id="" title="" name="" detail="" actions="" />
        <resource id="" title="" name="" detail="" actions="" />
        <resource id="" title="" name="" detail="" actions="">
            <resource id="" title="" name="" detail="" actions="" />
            <resource id="" title="" name="" detail="" actions="" />
            <resource id="" title="" name="" detail="" actions="">
                <resource id="" title="" name="" detail="" actions="" />
                <resource id="" title="" name="" detail="" actions="" >
                    <resource id="" title="" name="" detail="" actions="" ></resource>
                    <resource id="" title="" name="" detail="" actions="" ></resource>
                </resource>
                <resource id="" title="" name="" detail="" actions="" />
            </resource>
            <resource id="" title="" name="" detail="" actions="" />
            <resource id="" title="" name="" detail="" actions="" />
        </resource>
    </module>
</modules>
 

 

2。解析xml 文件

try {
             DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
             DocumentBuilder db = dbf.newDocumentBuilder();
             Document doc = db.parse(TbRole.class.getResourceAsStream("/com/role/module.xml"));
             Element root = doc.getDocumentElement();
             NodeList nl = root.getElementsByTagName("module");
             System.out.println("== " + nl.item(0).getAttributes().getNamedItem("title").getNodeValue());
             
        }
        catch(Exception e) {
            e.printStackTrace();
        }
 

 

 

 

3.生成xml 文件 由于document 本身没有out 输出流所以使用了Transformert

 

DocumentBuilderFactory documentBuilder = DocumentBuilderFactory.newInstance(); DocumentBuilder documentWrite = documentBuilder.newDocumentBuilder(); Document docWriter = documentWrite.newDocument(); docWriter.setXmlVersion("1.0"); Element root = docWriter.createElement("usb"); root.setAttribute("id","2"); root.setAttribute("name","liuqing"); root.setAttribute("version","1.2"); root.setAttribute("value","567"); Element student1 = docWriter.createElement("student"); student1.setAttribute("dir","q_1"); Element sid = docWriter.createElement("id"); sid.setAttribute("column", "id"); sid.setAttribute("type", "varchar"); sid.setAttribute("size", "13"); Element sage = docWriter.createElement("age"); sage.setAttribute("id", "23"); sage.setAttribute("column", "varchar(255)"); sage.setAttribute("name", "liuqing"); sage.setAttribute("type", "java.lang.String"); sage.setAttribute("class", "com.repastsystem.zik.entiy.StudentInfo"); sage.appendChild(docWriter.createTextNode("23")); docWriter.appendChild(sid); Element name = docWriter.createElement("name"); name.appendChild(docWriter.createTextNode("刘庆")); student1.appendChild(sid); student1.appendChild(sage); student1.appendChild(name); root.appendChild(student1); docWriter.appendChild(root); Transformer t = TransformerFactory.newInstance().newTransformer(); t.transform(new DOMSource(docWriter), new StreamResult(new FileOutputStream(new File("f:\\usb.xml"))));


 

4. 生成xml

 

  <?xml version="1.0" encoding="UTF-8" standalone="no"?> <usb id="2" name="liuqing" value="567" version="1.2"> <student dir="q_1"> <id column="id" size="13" type="varchar"/> <age class="com.repastsystem.zik.entiy.StudentInfo" column="varchar(255)" id="23" name="liuqing" type="java.lang.String">23</age> <name>刘庆</name> </student> </usb>


 

 

 

 

 

 

分享到:
评论

相关推荐

    基于state pattern实现的xml解释器

    在这个案例中,“基于state pattern实现的xml解释器”指的是一个XML解析器,该解析器在解析XML文档的过程中,根据不同的解析状态(如开始标签、结束标签、文本节点等)执行相应的操作,从而实现灵活且可扩展的解析...

    Ant_的最完整build.xml解释,Ant入门与进阶

    《Ant的最完整build.xml解释:Ant入门与进阶》 Ant,作为Java世界中的一个构建工具,由Apache软件基金会开发,是项目管理和自动化构建的重要工具。它通过XML定义的build.xml文件,来描述项目的构建过程,包括编译、...

    简单xml解释器设计文档.zip_VS2010_vs2010 XML_简单xml解释器设计文档

    在本文中,我们将深入探讨一个基于VS2010开发的简易XML解释器的设计文档,该文档旨在解析和处理XML文档,帮助用户理解和操作XML数据。 一、VS2010开发环境介绍 Visual Studio 2010是微软公司推出的一款强大的开发...

    简单的XML解释器纯C语言写的

    本项目是一个使用纯C语言编写的简单XML解释器,专注于解析XML的基本语法,不涉及复杂的高级特性。 首先,我们来看`SimpleXmlParser.h`头文件。这个文件通常会包含函数声明,枚举类型,以及可能的数据结构定义。在...

    XML解释器TinyXml使用

    TinyXml是一个轻量级的XML解析库,专为C++设计,可以在Windows和Linux操作系统上运行。TinyXml库的核心特点是其基于DOM(Document Object Model)的解析方式,它将XML文档解析成内存中的数据结构,形成一棵XML树,...

    vc2005 xml 解释器 有源代码 不依赖任何库

    本项目提供的是一款基于VC2005编译环境的XML解释器,其特点在于提供了完整的源代码,并且不依赖任何外部库,这使得它在某些特定环境下更具优势,比如嵌入式系统或者对资源有限制的项目。 XML解释器的主要任务是解析...

    VC2008 xml 解释器 有源代码 不依赖任何库

    本资源提供了VC2008环境下编译的XML解释器的源代码,无需依赖任何外部库,这使得它在特定场景下具有较高的灵活性和便携性。 在Visual C++ 2008(简称VC2008)中,开发者通常会使用Microsoft的MFC(Microsoft ...

    Ant的最完整的build.xml解释

    ### Ant的最完整的build.xml解释 #### 一、Ant简介及背景 Ant 是一款非常实用且功能强大的构建工具,主要用于Java项目的编译、测试、部署等自动化任务处理。相较于传统的Make命令工具,Ant的设计更加现代化,它...

    pugixml最快的xml解释器

    **Pugixml:高效的XML解析库** 在IT行业中,数据交换和存储经常涉及XML(eXtensible Markup Language)格式。XML因其结构清晰、可读性强的特点,被广泛应用于配置文件、数据交换、文档存储等领域。然而,处理XML...

    android(登录、xml解释、适配器)

    在Android开发中,XML起着至关重要的作用,尤其在用户界面设计和数据存储方面。XML(eXtensible Markup Language)是一种标记语言,允许我们结构化地定义和表示数据。以下将详细介绍XML在Android中的应用,包括登录...

    linux C WebServer xml解释

    linux c++实现http web server 支持所有浏览器 修改... 本机ip地址配置在ip.conf(xml格式)文件下,运行程序务必修改该文件的i对应本机的ip地址 由于资源的相对路径问题 如果不想修改代码请到Debug程序目录运行程序

    开源xml解析器.doc

    Expat 是一个开源的 XML 解析器,由 C 语言编写,最初是 Mozilla 项目的一部分。它的主要开发者是 James Clark,他还开发了其他知名的软件工具,如 groff、Jade、XP(Java XML 解析器包)和 XT(Java XSL 引擎)。...

    XML初学入门教程(pdf)

    微软开发了自己的 XML 解释器,支持在 Windows 系统上处理 XML 文档。这包括了: 1. **MSXML**:微软的 XML 解析库,支持多种编程语言。 2. **Internet Explorer 支持**:IE 提供了对 XML 和 XSLT 的内置支持。 ##...

    Vc++ 解析Xml(用于Landsat元数据)

    在IT行业中,XML(eXtensible Markup Language)是一种广泛使用的数据交换格式,它允许结构化数据的存储和传输。在“Vc++ 解析Xml(用于Landsat元数据)”这个主题中,我们将深入探讨如何使用C++来解析大规模的XML...

    Ant_的最完整build.xml解释

    Ant的概念 Make命令是一个项目管理工具,而Ant所实现功能与此类似。像make,gnumake和nmake这些编译工具都有一定的缺陷,但是Ant却克服了这些工具的缺陷。最初Ant开发者在开发跨平台的应用时,用样也是基于这些缺陷...

    XML.rar_c xml_visual c_xml二叉树

    在这个“XML.rar_c xml_visual c_xml二叉树”项目中,我们主要探讨的是XML解释器的算法实现,它能用来展示XML数据结构为可视化的二叉树形式。 首先,我们要理解XML的基本概念。XML是一种自描述性的文本格式,通过...

    libxml2-2.9.8.rar_C语言解析XML_ITW_c语言XML解析器_joined4mf_windows 8

    《C语言实现的libxml2-2.9.8 XML解析器详解》 XML(Extensible Markup Language)是一种用于标记数据的语言,广泛应用于网络数据交换、配置文件存储等领域。在IT行业中,C语言由于其高效、灵活的特点,常被用来编写...

    目标检测数据集:智能小车赛道自动驾驶、交通指示牌目标检测数据集(VOC标注格式的xml文件,已经做了训练集和测试集划分)

    训练集共901张jpg图片和901个xml解释文件。训练集共225张jpg图片和225个xml解释文件 【json文件】8类别的json字典文件 为了方便查看数据,提供了可视化py文件,随机传入一张图片即可绘制边界框,并且保存在当前目录...

    很经典的XML入门教程

    #### 第六章:微软的XML解释器 微软提供了一系列工具和技术来处理XML数据,其中包括MSXML库,这是一套COM组件,用于解析和处理XML数据。开发者可以使用VBScript、JScript或.NET Framework中的类库来访问这些组件。 ...

    XML入门教程

    本教程将通过多个章节介绍XML的基础知识和应用实例,如XML的语法、DTD的定义、XML在不同浏览器中的表现、微软的XML解释器、XML DOM(文档对象模型)、XSL(扩展样式表语言)等。通过逐步学习,初学者将能够掌握XML的...

Global site tag (gtag.js) - Google Analytics