我希望将XML1转换为XML2(基本上添加额外的命名空间& )。
我被告知这可以通过XSLT完成。这是可以使用XSLT实现的吗?它有多简单(或复杂)?
XML1
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Update_WCS_OrderStatus SYSTEM "Update_WCS_OrderStatus_20.dtd" >
<Update_WCS_OrderStatus>
<ControlArea>
<Verb value="Constant">test</Verb>
<Noun value="Constant">Constant</Noun>
<Credentials>
<LogonId>a</LogonId>
<Password>b</Password>
</Credentials>
</ControlArea>
<DataArea>
<OrderStatus>
<OrderStatusHeader>
<OrderNumber/>
</OrderStatusHeader>
<OrderStatusItem>
<ItemNumber/>
</OrderStatusItem>
</OrderStatus>
</DataArea>
</Update_WCS_OrderStatus>'
XML2
'<?xml version="1.0" encoding="UTF-8"?>
<ns0:Messages xmlns:ns0="http://sap.com/xi/XI/SplitAndMerge">
<ns0:Message1>
<!DOCTYPE Update_WCS_OrderStatus SYSTEM "Update_WCS_OrderStatus_20.dtd" >
<Update_WCS_OrderStatus>
<ControlArea>
<Verb value="">Constant</Verb>
<Noun value="">Constant</Noun>
<Credentials>
<LogonId>test</LogonId>
<Password>test</Password>
</Credentials>
</ControlArea>
<DataArea>
<OrderStatus>
<OrderStatusHeader>
<OrderNumber/>
</OrderStatusHeader>
<OrderStatusItem>
<ItemNumber/>
</OrderStatusItem>
</OrderStatus>
</DataArea>
</Update_WCS_OrderStatus>
</ns0:Message1>
</ns0:Messages>
答案 0 :(得分:1)
您不能在元素节点内部拥有DOCTYPE节点。 除此之外,您当然可以使用XSLT完成任务:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:ns0="http://sap.com/xi/XI/SplitAndMerge">
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/">
<ns0:Messages>
<ns0:Message1>
<xsl:apply-templates/>
</ns0:Message1>
</ns0:Messages>
</xsl:template>
<xsl:template match="ControlArea/Verb[@value = 'Constant'] | ControlArea/Noun[@value = 'Constant']">
<Verb value="">Constant</Verb>
</xsl:template>
</xsl:stylesheet>