【问题标题】:remove namespaces, attributes, Xsi from Soap response using code or XSLT使用代码或 XSLT 从 Soap 响应中删除名称空间、属性、Xsi
【发布时间】:2016-07-05 09:09:12
【问题描述】:

使用代码或 XSLT 从 Soap 响应中删除命名空间、属性、Xsi

想要使用 C# 代码(Serializer、XMLDoc、XDoc)或 XSLT 将 soap 响应转换为普通 XML(没有命名空间、属性)。

这里是肥皂响应。

            <?xml version="1.0" encoding="UTF-8"?>
            <SOAP-ENV:Envelope
                xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
                xmlns:ns1="urn:Magento"
                xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
                <SOAP-ENV:Body>
                    <ns1:catalogProductInfoResponse>
                        <info xsi:type="ns1:catalogProductReturnEntity">
                            <product_id xsi:type="xsd:string">3459</product_id>
                            <sku xsi:type="xsd:string">HK-BP001</sku>
                            <categories SOAP-ENC:arrayType="xsd:string[0]" xsi:type="ns1:ArrayOfString"/>
                            <websites SOAP-ENC:arrayType="xsd:string[7]" xsi:type="ns1:ArrayOfString">
                                <item xsi:type="xsd:string">1</item>                                
                            </websites>
                            <created_at xsi:type="xsd:string">2016-04-19 01:45:35</created_at>
                            <has_options xsi:type="xsd:string">1</has_options>
                            <special_from_date xsi:type="xsd:string">2016-04-19 00:00:00</special_from_date>
                            <tier_price SOAP-ENC:arrayType="ns1:catalogProductTierPriceEntity[0]" xsi:type="ns1:catalogProductTierPriceEntityArray"/>
                            <custom_design xsi:type="xsd:string">ultimo/default</custom_design>
                            <enable_googlecheckout xsi:type="xsd:string">1</enable_googlecheckout>
                        </info>
                    </ns1:catalogProductInfoResponse>
                </SOAP-ENV:Body>
            </SOAP-ENV:Envelope>

我想要转换的 xml 像:

            <?xml version="1.0" encoding="UTF-8"?>
            <Envelope>
                <Body>
                    <catalogProductInfoResponse>
                        <info>
                            <product_id>3459</product_id>
                            <sku>HK-BP001</sku>
                            <categories/>
                            <websites>
                                <item>1</item>                              
                            </websites>
                            <created_at>2016-04-19 01:45:35</created_at>
                            <has_options>1</has_options>
                            <special_from_date>2016-04-19 00:00:00</special_from_date>
                            <tier_price/>
                            <custom_design>ultimo/default</custom_design>
                            <enable_googlecheckout>1</enable_googlecheckout>
                        </info>
                    </catalogProductInfoResponse>
                </Body>
            </Envelope>

【问题讨论】:

    标签: c# xml xslt


    【解决方案1】:

    您可以使用 XSLT:

    <xsl:template match="*">
      <xsl:element name="{local-name()}">
        <xsl:apply-templates/>
      </xsl:element>
    </xsl:template>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多