1

単純な XML があり、//*[@isDigSignReqd = 'true'] のような XPATH クエリを使用して XML に署名しました。現在、署名された XML には次のような属性が含まれています。

xmlns="http://www.xyze.org/xservice" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

すべてのノードに接続されています。XML 署名の検証は正常に行われます。しかし、これらの属性を削除できますか。私は XML 署名とそのすべてにかなり慣れていません。助けてください。

これはXMLがどのように見えるかです(一部)


<?xml version="1.0" encoding="UTF-8"?><XService xmlns="http://www.xyzbe.org/xservice" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.xyzbe.org/xservice ACPDTLRequest.xsd">
 <request xmlns="http://www.xyzbe.org/xservice" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <header xmlns="http://www.xyzbe.org/xservice" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <BANK_ID isDigSignReqd="true" xmlns="http://www.xyzbe.org/xservice" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">DBS</BANK_ID>
   <LANGUAGE_ID isDigSignReqd="true" xmlns="http://www.xyzbe.org/xservice" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">001</LANGUAGE_ID>
   <CHANNEL_ID isDigSignReqd="true" xmlns="http://www.xyzbe.org/xservice" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">I</CHANNEL_ID>
   <LOGIN_FLAG isDigSignReqd="true" xmlns="http://www.xyzbe.org/xservice" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">2</LOGIN_FLAG>

変換はこのように作成されます。

final XPathFilter2ParameterSpec xp2Spec = new XPathFilter2ParameterSpec(
Collections.singletonList(new XPathType("//*[@isDigSignReqd='true']", XPathType.Filter.INTERSECT)));
List<Transform> transforms = new ArrayList<Transform>() {
    private static final long serialVersionUID = 1L;
         {
    add(sigFactory.newTransform(Transform.ENVELOPED, (TransformParameterSpec) null));
    add(sigFactory.newTransform(Transform.XPATH2, xp2Spec ));
        } };

4

1 に答える 1

0

現在、署名された XML には次のような属性が含まれています。

xmlns="http://www.xyze.org/xservice" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

すべてのノードに接続されています。XML 署名の検証は正常に行われます。しかし、これらの属性を削除できますか。

はい、提供された XML ドキュメントは次と同等です。

<XService xsi:schemaLocation="http://www.xyzbe.org/xservice ACPDTLRequest.xsd"
          xmlns="http://www.xyzbe.org/xservice" 
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <request>
    <header>
      <BANK_ID isDigSignReqd="true">DBS</BANK_ID>
      <LANGUAGE_ID isDigSignReqd="true">001</LANGUAGE_ID>
      <CHANNEL_ID isDigSignReqd="true">I</CHANNEL_ID>
      <LOGIN_FLAG isDigSignReqd="true">2</LOGIN_FLAG>
    </header>
  </request>
</XService>

説明:

デフォルトの名前空間は、子孫要素のすべての名前で有効であり、指定する必要はありません。

不要な名前空間ノードまたは宣言を取り除く方法は?

以下は、恒等変換を使用した単純な XSLT ソリューションです。

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

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

この変換が提供された XML ドキュメントに適用された場合(整形式になるように修正):

<XService xmlns="http://www.xyzbe.org/xservice" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.xyzbe.org/xservice ACPDTLRequest.xsd">
    <request xmlns="http://www.xyzbe.org/xservice" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <header xmlns="http://www.xyzbe.org/xservice" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <BANK_ID isDigSignReqd="true" xmlns="http://www.xyzbe.org/xservice" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">DBS</BANK_ID>
            <LANGUAGE_ID isDigSignReqd="true" xmlns="http://www.xyzbe.org/xservice" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">001</LANGUAGE_ID>
            <CHANNEL_ID isDigSignReqd="true" xmlns="http://www.xyzbe.org/xservice" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">I</CHANNEL_ID>
            <LOGIN_FLAG isDigSignReqd="true" xmlns="http://www.xyzbe.org/xservice" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">2</LOGIN_FLAG>
        </header>
    </request>
</XService>

結果は次のとおりです。

<XService xsi:schemaLocation="http://www.xyzbe.org/xservice ACPDTLRequest.xsd"
          xmlns="http://www.xyzbe.org/xservice" 
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <request>
    <header>
      <BANK_ID isDigSignReqd="true">DBS</BANK_ID>
      <LANGUAGE_ID isDigSignReqd="true">001</LANGUAGE_ID>
      <CHANNEL_ID isDigSignReqd="true">I</CHANNEL_ID>
      <LOGIN_FLAG isDigSignReqd="true">2</LOGIN_FLAG>
    </header>
  </request>
</XService>
于 2011-02-28T17:04:26.110 に答える