我正在寻找一个批处理脚本,它可以复制所有父元素,其子元素在 xml 文件中具有<![CDATA[
....]]>
并输出到新的 xml 文件。
这是我的xml文件:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<books xmlns:jndi="urn:jboss:jndi-binding-service:1.0">
<jndi:bindings>
<jndi:binding name="property/category/books/book1">
<jndi:value type="java.lang.String">
<![CDATA[
<?xml version="1.0" encoding="ISO-8859-1"?>
<urlConfig>
<defaults catID="1983" subcatID="1987" method="get" onError="keep"/>
<urlKey name="logo" altURL="def.com">
<address>abc.com</address>
</urlKey>
<urlKey name="logo1" altURL="def.com">
<address>abc.com</address>
</urlKey>
</urlConfig>
]]>
</jndi:value>
</jndi:binding>
<jndi:binding name="property/category/books/book2">
<jndi:value type="java.lang.String">
abc.com
</jndi:value>
</jndi:binding>
<jndi:binding name="property/category/books/book3">
<jndi:value type="java.lang.String">
<![CDATA[
<?xml version="1.0" encoding="ISO-8859-1"?>
<urlConfig>
<defaults catID="1989" subcatID="1987" method="get" onError="keep"/>
<urlKey name="logo" altURL="def.com">
<address>abc.com</address>
</urlKey>
<urlKey name="logo1" altURL="def.com">
<address>abc.com</address>
</urlKey>
</urlConfig>
]]>
</jndi:value>
</jndi:binding>
<jndi:binding name="property/category/books/book4">
<jndi:value type="java.lang.String">
<![CDATA[
<?xml version="1.0" encoding="ISO-8859-1"?>
<urlConfig>
<defaults catID="1990" subcatID="1987" method="get" onError="keep"/>
<urlKey name="logo" altURL="def.com">
<address>abc.com</address>
</urlKey>
<urlKey name="logo1" altURL="def.com">
<address>abc.com</address>
</urlKey>
</urlConfig>
]]>
</jndi:value>
</jndi:binding>
<jndi:binding name="property/category/books/book5">
<jndi:value type="java.lang.String">
abc.com
</jndi:value>
</jndi:binding>
</jndi:bindings>
</books>
因此,预期的输出必须捕获其子元素具有<![CDATA[
...的所有父元素]]>
。在此示例中,父元素是<jndi:binding name="property/category/books/book#">
.
预期输出为:output.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<books xmlns:jndi="urn:jboss:jndi-binding-service:1.0">
<jndi:bindings>
<jndi:binding name="property/category/books/book1">
<jndi:value type="java.lang.String">
<![CDATA[
<?xml version="1.0" encoding="ISO-8859-1"?>
<urlConfig>
<defaults catID="1983" subcatID="1987" method="get" onError="keep"/>
<urlKey name="logo" altURL="def.com">
<address>abc.com</address>
</urlKey>
<urlKey name="logo1" altURL="def.com">
<address>abc.com</address>
</urlKey>
</urlConfig>
]]>
</jndi:value>
</jndi:binding>
<jndi:binding name="property/category/books/book3">
<jndi:value type="java.lang.String">
<![CDATA[
<?xml version="1.0" encoding="ISO-8859-1"?>
<urlConfig>
<defaults catID="1989" subcatID="1987" method="get" onError="keep"/>
<urlKey name="logo" altURL="def.com">
<address>abc.com</address>
</urlKey>
<urlKey name="logo1" altURL="def.com">
<address>abc.com</address>
</urlKey>
</urlConfig>
]]>
</jndi:value>
</jndi:binding>
<jndi:binding name="property/category/books/book4">
<jndi:value type="java.lang.String">
<![CDATA[
<?xml version="1.0" encoding="ISO-8859-1"?>
<urlConfig>
<defaults catID="1990" subcatID="1987" method="get" onError="keep"/>
<urlKey name="logo" altURL="def.com">
<address>abc.com</address>
</urlKey>
<urlKey name="logo1" altURL="def.com">
<address>abc.com</address>
</urlKey>
</urlConfig>
]]>
</jndi:value>
</jndi:binding>
</jndi:bindings>
</books>
我想使用 xml 处理器,xslt 来处理 xml 文件,但是如果文件中包含 CDATA 部分,xslt 处理器就不容易处理 xml 文件。