1

石鹸メッセージから石鹸エンベロープを削除する必要があります。そのためには、Java ではなく XSLT を使用します。このようなタイプのxmlを操作するには、より適切なソリューションです。

たとえば、私は石鹸のメッセージを持っています:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
                  xmlns:tar="namespace" 
                  xmlns:tar1="namespace">
    <soapenv:Header/>
    <soapenv:Body>
        <tar:RegisterUser>
            <tar1:Source>?</tar1:Source>
            <tar1:Profile>
                <tar1:EmailAddress>?</tar1:EmailAddress>

            </tar1:Profile>
        </tar:RegisterUser>
    </soapenv:Body>
</soapenv:Envelope>

そして、出力を次のようにしたい:

<tar:RegisterUser xmlns:tar="namespace" xmlns:tar1="namespace">
    <tar1:Source>?</tar1:Source>
    <tar1:Profile>
        <tar1:EmailAddress>?</tar1:EmailAddress>

    </tar1:Profile>
</tar:RegisterUser>

誰かがこれを行う方法についていくつかのアイデアを提供できますか?

4

2 に答える 2

8

これにより、soapenv:要素名前空間宣言が削除されます。

<xsl:stylesheet 
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
>
  <xsl:output indent="yes" />

  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()" />
    </xsl:copy>
  </xsl:template>

  <xsl:template match="soapenv:*">
    <xsl:apply-templates select="@* | node()" />
  </xsl:template>
</xsl:stylesheet>

結果:

<tar:RegisterUser xmlns:tar="namespace">
  <tar1:Source xmlns:tar1="namespace">?</tar1:Source>
  <tar1:Profile xmlns:tar1="namespace">
    <tar1:EmailAddress>?</tar1:EmailAddress>
  </tar1:Profile>
</tar:RegisterUser>
于 2012-07-27T15:54:58.233 に答える
2
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    version="1.0">

    <xsl:output method="xml" indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="/">
        <xsl:copy-of select="/soapenv:Envelope/soapenv:Body/*"/>
    </xsl:template>
</xsl:stylesheet>

出力:

<?xml version="1.0" encoding="utf-8"?>
<tar:RegisterUser xmlns:tar="namespace" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tar1="namespace">
    <tar1:Source>?</tar1:Source>
    <tar1:Profile>
        <tar1:EmailAddress>?</tar1:EmailAddress>
    </tar1:Profile>
</tar:RegisterUser>

xmlns:soapenv残念ながら、属性を簡単に削除する方法は見つかりませんでした。

于 2012-07-27T15:37:56.440 に答える