XML 创建和编辑工具 xmodifier

码农软件 · 软件分类 · XML相关工具 · 2019-09-17 17:43:15

软件介绍

xmodifier 是使用 XPATH 创建或者更 XML。XPATH 可以用来搜索 XML,但是有时候也可以用来编辑或者创建 XML:

XPath Value Desc
/ns:root/ns:element1 add <ns:element1/>
/ns:root/ns:element2[@attr=1] add <ns:element2 attr="1"/>
/ns:root/ns:element2/@attr 1 add <ns:element2 attr="1"/>
/ns:root/ns:element1/ns:element11 add <ns:element11/>
/ns:root/ns:element3 TEXT add <ns:element3>TEXT</ns:element3>
/ns:root/ns:element1[ns:element12]/ns:element13 add <ns:element13/>
//PersonList/Person[2]/Name NewName set the second Person node's Name Text
//PersonList/Person[2]/Name/text() NewName set the second Person node's Name Text
//PersonList/Person[1]/Name(:delete) delete this Name node
//PersonList/Person(:add)/Name NewName alway add a new Person node
//PersonList/Person(:insertBefore(Person[Name='Name2']))/Name NewName add a new Person node before Person named "Name2"

代码示例:

创建新的 XML

Document document = createDocument(); //empty document
    XModifier modifier = new XModifier(document);
    modifier.setNamespace("ns", "http://localhost");
    // create an empty element
    modifier.addModify("/ns:root/ns:element1");
    // create an element with attribute
    modifier.addModify("/ns:root/ns:element2[@attr=1]");
    // append an new element to existing element1
    modifier.addModify("/ns:root/ns:element1/ns:element11");
    // create an element with text
    modifier.addModify("/ns:root/ns:element3", "TEXT");
    modifier.modify();

XML:

<root xmlns="http://localhost">
        <element1>
            <element11/>
        </element1>
        <element2 attr="1"/>
        <element3>TEXT</element3>
    </root>

修改现有的 XML:

原始 XML:

<root xmlns="http://localhost">
        <element1>
            <element11></element11>
        </element1>
        <element1>
            <element12></element12>
        </element1>
        <element2></element2>
        <element3></element3>
</root>
Document document = readDocument("modify.xml");
    XModifier modifier = new XModifier(document);
    modifier.setNamespace("ns", "http://localhost");
    modifier.addModify("/ns:root/ns:element1[ns:element12]/ns:element13");
    modifier.modify();

修改之后的 XML:

<root xmlns="http://localhost">
        <element1>
            <element11/>
        </element1>
        <element1>
            <element12/>
            <element13/>
        </element1>
        <element2/>
        <element3/>
    </root>

添加了新元素 ns:element13

本文地址:https://codercto.com/soft/d/14811.html

社群营销实战手册

社群营销实战手册

秋叶、邻三月、秦阳 / 人民邮电出版社 / 2018-1 / 69.00元

互联网正从“物以类聚”,走向“人以群分”的时代。秋叶等人的“社群营销”,并非单纯靠社群卖东西,而是建立一种中心化的、自行运转的生态,让“同好”们形成紧密的联系,创造出海量营销机会。 《社群营销实战手册 从社群运营到社群经济》共5章内容,从社群的定位、建立、扩张、变现、运营,到社群的生命周期延长、社群运营团队的打造和管理以及社群管理工具,大量干货秘笈一应俱全,并提供丰富的运营实战案例,全面解读社群的......一起来看看 《社群营销实战手册》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

SHA 加密
SHA 加密

SHA 加密工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具