0
我有一个程序可以生成XML输出。 默认命名空间中的程序是这样的:无法更新XML文档的名称空间
<n0:eCPR xmlns:n0="http://www.dir.ca.gov/dlse/CPR-Prod-Test/CPR.xsd"
xmlns:prx="urn:sap.com:proxy:DV4:/1SAI/TAS1F59A417878D36573F1D:700:2013/05/24">
<n0:contractorInfo>
<n0:contractorName>test_user</n0:contractorName>
<n0:contractorAddress>
<n0:street></n0:street>
<n0:city></n0:city>
<n0:state/>
<n0:zip/>
</n0:contractorAddress>
</n0:contractorInfo>
</n0:eCPR>
如果我删除默认的命名空间,输出看起来像这样
<eCPR>
<contractorInfo>
<contractorName>test_user</contractorName>
<contractorAddress>
<street></street>
<city></city>
<state/>
<zip/>
</contractorAddress>
<insuranceNum></insuranceNum>
<contractorEmail></contractorEmail>
</contractorInfo>
</eCPR>
什么,我希望它看起来像
<CPR:eCPR xmlns:CPR="http://www.dir.ca.gov/dlse/CPR-Prod-Test/CPR.xsd">
<CPR:contractorInfo>
<CPR:contractorName>test_user</CPR:contractorName>
<CPR:contractorAddress>
<CPR:street>999 Carrier Rd</CPR:street>
<CPR:city>Oakland</CPR:city>
<CPR:state>CA</CPR:state>
<CPR:zip>94612</CPR:zip>
</CPR:contractorAddress>
</CPR:contractorInfo>
</CPR:eCPR>
我用来删除默认命名空间的代码是:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/|comment()|processing-instruction()">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
请帮忙。
感谢
你的问题不清楚。什么是实际的XML输入? –
@ michael.hor257k我正在读取XSD并获取每个节点的值并生成XML输出。初始输出包含以sap://开头的namspaces,因为它是一个SAP系统。但是,我想将名称空间更新为CPR(如图所示)。我删除了现有的名称空间,但无法更新它。我更新了默认输出 –