我正在从类似的SharePoint应用程序获得响应
输入
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<SharepointResponse xmlns="http://test.com.services.generic">
<Sharepoint_Response><?xml version="1.0" encoding="UTF-8"?>
<CopyIntoItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<CopyIntoItemsResult>0</CopyIntoItemsResult>
<Results>
<CopyResult ErrorCode="Success" DestinationUrl="http://archivelink.dev.test.com/"/>
</Results>
</CopyIntoItemsResponse></Sharepoint_Response>
</SharepointResponse>
</Body>
</Envelope>
我正在使用此代码
代码:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes" encoding="utf-8"/>
<!--Identity template simply copies content forward -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates select="*" />
<xsl:value-of select="text()" disable-output-escaping="yes"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
输出:
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<SharepointResponse xmlns="http://test.com.services.generic">
<Sharepoint_Response><?xml version="1.0" encoding="UTF-8"?>
<CopyIntoItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<CopyIntoItemsResult>0</CopyIntoItemsResult>
<Results>
<CopyResult ErrorCode="Success" DestinationUrl="http://archivelink.dev.test.com/enterprise/"/>
</Results>
</CopyIntoItemsResponse></Sharepoint_Response>
</SharepointResponse>
</Body>
</Envelope>
我不知道如何在<Sharepoint_Response>
之后删除此<?xml version="1.0" encoding="UTF-8"?>
预期输出:
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<SharepointResponse xmlns="http://test.com.services.generic">
<Sharepoint_Response>
<CopyIntoItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<CopyIntoItemsResult>0</CopyIntoItemsResult>
<Results>
<CopyResult ErrorCode="Success" DestinationUrl="http://archivelink.dev.test.com/enterprise/"/>
</Results>
</CopyIntoItemsResponse></Sharepoint_Response>
</SharepointResponse>
</Body>
</Envelope>
你可以试试这样的东西:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes" encoding="utf-8" />
<!--Identity template simply copies content forward -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates select="*" />
<xsl:value-of select="substring-after(text(),'?>')" disable-output-escaping="yes" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
其思想是使用substring-after
来获取XML声明的?>
部分结束后的所有内容。使用该样式表得到了以下输出:
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<SharepointResponse xmlns="http://test.com.services.generic">
<Sharepoint_Response>
<CopyIntoItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<CopyIntoItemsResult>0</CopyIntoItemsResult>
<Results>
<CopyResult ErrorCode="Success" DestinationUrl="http://archivelink.dev.test.com/"/>
</Results>
</CopyIntoItemsResponse></Sharepoint_Response></SharepointResponse></Body></Envelope>