有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何拆分XML

我在这里的第一篇帖子。我已经找过了,但还没有找到我要找的东西

我真的不确定我需要什么技巧来完成下面的工作

我使用Mule 3.3 CE,需要拆分XML文件。我需要在每个分割的XML中保留“rootElement”及其属性。所有XML文件都将被丢弃在同一个JMS队列中

我知道如何分割三个产品节点,但如何在每个XML文件上保留“rootElement”

XPath?XSLT?删除和添加节点? 我更喜欢XPath,但它有能力做到这一点吗

<?xml version="1.0" encoding="ISO-8859-1"?>
<rootElement xmlns="http://Ecommerce.com/schemas/loyalist/3"
           preOrderTo="2012-12-31T23:59:59"
           currency="GBP"
           timeStamp="2012-08-15T23:59:59">
  <Product
             itemID="09999-3-"
             name="Plate"
             description="Plate of blue man"
             tax="0.00"
             eanCode="1234567890123"
             eanType="EAN 13"/>
  <priceBracket quantity="1"
            price="10.98"
            grossPrice="13.00"/>
  <Product
             itemID="12345-3-"
             name="Plate"
             description="Plate of black man"
             tax="0.00"
             eanCode="1234569870123"
             eanType="EAN 13"/>
  <priceBracket quantity="1"
            price="15.98"
            grossPrice="18.00"/>
  <Product
             itemID="98765-3-"
             name="Plate"
             description="Plate of yellow man"
             tax="0.00"
             eanCode="7894567890123"
             eanType="EAN 13"/>
  <priceBracket quantity="1"
            price="20.98"
            grossPrice="24.00"/>
</rootElement>

我在Mule 3.3 CE中需要的是以下拆分:

一,

<?xml version="1.0" encoding="ISO-8859-1"?>
<rootElement xmlns="http://Ecommerce.com/schemas/loyalist/3"
           preOrderTo="2012-12-31T23:59:59"
           currency="GBP"
           timeStamp="2012-08-15T23:59:59">
<Product
             itemID="09999-3-"
             name="Plate"
             description="Plate of blue man"
             tax="0.00"
             eanCode="1234567890123"
             eanType="EAN 13"/>
<priceBracket quantity="1"
            price="10.98"
            grossPrice="13.00"/>
</rootElement>

二,

<?xml version="1.0" encoding="ISO-8859-1"?>
<rootElement xmlns="http://Ecommerce.com/schemas/loyalist/3"
           preOrderTo="2012-12-31T23:59:59"
           currency="GBP"
           timeStamp="2012-08-15T23:59:59">
  <Product
             itemID="12345-3-"
             name="Plate"
             description="Plate of black man"
             tax="0.00"
             eanCode="1234569870123"
             eanType="EAN 13"/>
  <priceBracket quantity="1"
            price="15.98"
            grossPrice="18.00"/>
</rootElement>

三,

<?xml version="1.0" encoding="ISO-8859-1"?>
<rootElement xmlns="http://Ecommerce.com/schemas/loyalist/3"
           preOrderTo="2012-12-31T23:59:59"
           currency="GBP"
           timeStamp="2012-08-15T23:59:59">
  <Product
             itemID="98765-3-"
             name="Plate"
             description="Plate of yellow man"
             tax="0.00"
             eanCode="7894567890123"
             eanType="EAN 13"/>
  <priceBracket quantity="1"
            price="20.98"
            grossPrice="24.00"/>
</rootElement>

共 (0) 个答案