为XML元素添加ID

首先下载Apache xalan,http://xml.apache.org/xalan-j/downloads.html

使用windows命令行模式,因为我没有设置java path,所以使用了如下的命令行:

java -cp xalan.jar;serializer.jar;xml-apis.jar;xercesImpl.jar org.apache.xalan.xslt.Process -IN books.xml -XSL idmaker2.xsl -OUT test.xml

其中IN后面是你要转化的源文件

<?xml version="1.0" encoding="ISO-8859-1"?> <bookstore> <ack>Success</ack> <version>1.0.1</version> <timestamp>2009-10-13T16:32:00.614Z</timestamp> <book category="COOKING"> <title lang="en">Everyday Italian</title> <author>Giada De Laurentiis</author> <year>2005</year> <price>30.00</price> </book> <book category="CHILDREN"> <title lang="en">Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book> <book category="WEB"> <title lang="en">XQuery Kick Start</title> <author>James McGovern</author> <author>Per Bothner</author> <author>Kurt Cagle</author> <author>James Linn</author> <author>Vaidyanathan Nagarajan</author> <year>2003</year> <price>49.99</price> </book> <book category="WEB"> <title lang="en">Learning XML</title> <author>Erik T. Ray</author> <year>2003</year> <price>39.95</price> </book> </bookstore>

XSL后面是XSLT文件

<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" indent="yes" /> <xsl:template match="*"> <xsl:variable name="special-id"> <xsl:for-each select="ancestor-or-self::*"> <xsl:value-of select="generate-id(.)"/> </xsl:for-each> </xsl:variable> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:attribute name="ID"><xsl:value-of select="$special-id"/></xsl:attribute> <xsl:apply-templates/> </xsl:copy> </xsl:template> </xsl:stylesheet>

OUT是输出文件

<?xml version="1.0" encoding="UTF-8"?><bookstore ID="N10001"> <ack ID="N10001N10004">Success</ack> <version ID="N10001N10007">1.0.1</version> <timestamp ID="N10001N1000A">2009-10-13T16:32:00.614Z</timestamp> <book category="COOKING" ID="N10001N1000D"> <title lang="en" ID="N10001N1000DN10010">Everyday Italian</title> <author ID="N10001N1000DN10014">Giada De Laurentiis</author> <year ID="N10001N1000DN10017">2005</year> <price ID="N10001N1000DN1001A">30.00</price> </book> <book category="CHILDREN" ID="N10001N1001E"> <title lang="en" ID="N10001N1001EN10021">Harry Potter</title> <author ID="N10001N1001EN10025">J K. Rowling</author> <year ID="N10001N1001EN10028">2005</year> <price ID="N10001N1001EN1002B">29.99</price> </book> <book category="WEB" ID="N10001N1002F"> <title lang="en" ID="N10001N1002FN10032">XQuery Kick Start</title> <author ID="N10001N1002FN10036">James McGovern</author> <author ID="N10001N1002FN10039">Per Bothner</author> <author ID="N10001N1002FN1003C">Kurt Cagle</author> <author ID="N10001N1002FN1003F">James Linn</author> <author ID="N10001N1002FN10042">Vaidyanathan Nagarajan</author> <year ID="N10001N1002FN10045">2003</year> <price ID="N10001N1002FN10048">49.99</price> </book> <book category="WEB" ID="N10001N1004C"> <title lang="en" ID="N10001N1004CN1004F">Learning XML</title> <author ID="N10001N1004CN10053">Erik T. Ray</author> <year ID="N10001N1004CN10056">2003</year> <price ID="N10001N1004CN10059">39.95</price> </book> </bookstore>

参考:

http://xml.apache.org/xalan-j/commandline.html

http://lab.tojio.com/2009/03/06/unique-id-for-each-node-in-an-xml-file-en/

http://www.stylusstudio.com/xsllist/200512/post30240.html

http://www.roseindia.net/xml/dom/

转载于:https://www.cnblogs.com/ainima/archive/2009/11/05/6331354.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 Camunda BPM 中,可以通过在 BPMN 2.0 XML 文件的元素添加扩展属性来扩展节点。这些扩展属性可以存储与该元素相关的自定义数据。 以下是在 Camunda BPMN 2.0 XML 文件中添加扩展属性的步骤: 1. 打开你的 BPMN 2.0 XML 文件。 2. 在需要添加扩展属性的元素上,添加一个名为 camunda:属性名 的属性(其中“属性名”是你想要添加的属性名称)。 例如,如果你想要添加一个名为“myCustomProperty”的扩展属性,则应该在元素添加 camunda:myCustomProperty 属性。 3. 为 camunda:属性名 属性设置值,以存储自定义数据。 例如,如果你想要将 myCustomProperty 设置为“true”,则应该在元素上设置 camunda:myCustomProperty="true"。 4. 保存 BPMN 2.0 XML 文件。 以下是一个示例,演示如何在 BPMN 2.0 XML 文件中添加 camunda:myCustomProperty 扩展属性: ```xml <bpmn:serviceTask id="myServiceTask" name="My Service Task"> <bpmn:extensionElements> <camunda:properties> <camunda:property name="myCustomProperty" value="true" /> </camunda:properties> </bpmn:extensionElements> </bpmn:serviceTask> ``` 在此示例中,我们使用了 Camunda 的扩展元素添加一个名为 camunda:myCustomProperty 的属性。该属性的值为“true”。 请注意,在此示例中,我们将 camunda:myCustomProperty 添加到 bpmn:serviceTask 元素上。你可以将 camunda:属性名 添加到任何 BPMN 2.0 元素上,以存储与该元素相关的自定义数据。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值