我正在使用xades4j来生成xades签名。 我想在引用中包含xpath变换。我的问题是它是一个分离的签名,而xpath有名称空间......
我尝试使用以下xml(摘录):
<collection xmlns:t="http://test.xades4j/tracks" Id="root">
<album>
<title>Questions, unanswered</title>
<artist>Steve and the flubberblubs</artist>
<year>1989</year>
<t:tracks xmlns:t="http://test.xades4j/tracks">
<t:song length="4:05" tracknumber="1">
<t:title>What do you know?</t:title>
<t:artist>Steve and the flubberblubs</t:artist>
<t:lastplayed>2006-10-17-08:31</t:lastplayed>
</t:song>
<t:song length="3:45" tracknumber="2">
<t:title>Who do you know?</t:title>
<t:artist>Steve and the flubberblubs</t:artist>
<t:lastplayed>2006-10-17-08:35</t:lastplayed>
</t:song>
如果我尝试使用以下代码执行此文档的封装签名:
String xpathString = "/collection/album/t:tracks/t:song[ @tracknumber = 1 ]";
DataObjectDesc obj1 = new DataObjectReference("");
obj1.withTransform(new EnvelopedSignatureTransform());
obj1.withTransform(XPath2Filter.intersect( xpathString ));
SignedDataObjects objs = new SignedDataObjects( obj1 );
Document doc = getDocument(path+fileName);
signer.sign( objs, doc.getDocumentElement() );
它工作正常,引用看起来像这样:
<ds:Reference Id="xmldsig-44c42d30-9a42-4290-afba-b89dc807a668-ref0" URI="">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
<ds:Transform Algorithm="http://www.w3.org/2002/06/xmldsig-filter2">
<dsig-xpath:XPath xmlns:dsig-xpath="http://www.w3.org/2002/06/xmldsig-filter2" Filter="intersect">/collection/album/t:tracks/t:song[ @tracknumber = 1 ]</dsig-xpath:XPath>
</ds:Transform>
</ds:Transforms>
但是,如果我尝试分离版本,请使用代码:
String xpathString = "/collection/album/t:tracks/t:song[ @tracknumber = 1 ]";
DataObjectDesc obj1 = new DataObjectReference( fileName );
obj1.withTransform(XPath2Filter.intersect( xpathString ));
SignedDataObjects objs = new SignedDataObjects( obj1 );
objs.withBaseUri( "file:///"+path );
signer.sign( objs, db.newDocument());
我收到错误:前缀必须解析为命名空间:t
我的问题类似于此处描述的问题:namespace and xpath 但是没有答案,我所拥有的是有点不同。我请客人说这个问题的答案可以帮助我...
那么,如何在xades4j中将命名空间设置为变换?
答案 0 :(得分:0)
XPath
元素将包含名称空间声明。如果可能的话,我会对此进行测试并添加支持。