Skip to content

Kamijoucen/xm-xml

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

96 Commits
 
 
 
 
 
 

Repository files navigation

文档解析

<a name="test">
    <![CDATA[<name>lalala</name>]]>
    <b test="demaxiya"/>
    <b test="hehehehe"/>
</a>
DocumentResult result = DocumentResult.loadFile("D:\\xx.xml");
String name = resule.child("a").attr("name").getVal();
// test
String test = resule.child("a").child("b").attr("test").getVal();
// demaxiya
String test1 = resule.child("a").childs("b").get(1).attr("test").getVal();
// hehehehe
String test2 = resule.child("a").firstChildText();
// <name>lalala</name>
String xml = "<a><b name=\"wow\"/></a>";
DocumentResult result = DocumentResult.loadString(xml);
String val = result.child("a").child("b").attr("name").getVal();
// wow

文档创建

创建如下文档:

<a name="test">
    <![CDATA[<name>lalala</name>]]>
    <b test="12345"/>
    <b test="12345"/>
</a>
DocumentTemplate template = DocumentTemplate.createDocument("a");
template.addAttr(new AttrNode("name", "test"));
template.addChild(new TextNode("<name>lalala</name>"));
TagBlockNode tag = new TagBlockNode("b");
tag.addAttr(new AttrNode("test", "12345"));
template.addChild(tag);
template.addChild(tag);
System.out.println(template.builder()); // 输出
System.out.println(template.formatBuilder()); // 格式化输出

About

java xml parser

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages