You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@santuario.apache.org by Hess Yvan <yv...@imtf.ch> on 2004/10/04 10:32:03 UTC

Problem of retrieving signature element using XPath expression ha ving different namespaces

Hi,

I have a problem to retrieve the Signature element of my signed XML document
using XPath expression. My document looks like that:

<?xml version="1.0" encoding="UTF-8"?>
<edoc:e-document xmlns:dcmi="http://www.imtf.com/e-document/dcmi"
xmlns:edoc="http://www.imtf.com/e-document"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0">
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
  ....
</ds:Signature>
   <edoc:metadata>
      <dcmi:DCMI>
 
<dcmi:identifier>urn:hypersuite:EFECD0FF-C0A8021C08DEE071-D030940E</dcmi:ide
ntifier>
         <dcmi:date>1966-07-20</dcmi:date>
      </dcmi:DCMI>
      <edoc:custom>
         <edoc:customer>333777</edoc:customer>
         <edoc:account>333777.0</edoc:account>
         <edoc:account-manager>Giraffe aile</edoc:account-manager>
         <edoc:amount>123456789.10</edoc:amount>
         <edoc:type>Savane</edoc:type>
      </edoc:custom>
   </edoc:metadata>
</edoc:e-document>

I would like to retrieve my signature element using the XPath expression
"/edoc:e-document/ds:Signature", but it fails because the namespace "edoc"
is not known if I use 

Element nscontext = XMLUtils.createDSctx(xmlDocument, "ds",
Constants.SignatureSpecNS);
sigElement = (Element) XPathAPI.selectSingleNode(xmlDocument,
signatureLocation, nscontext);

and it fails also if I use 

sigElement = (Element) XPathAPI.selectSingleNode(xmlDocument,
signatureLocation);

How can I solve the problem (I don't want to use "//ds:Signature") . It seem
to be a problem of Xalan XPath API....

Thanks for your answer

Yvan

Re: Problem of retrieving signature element using XPath expression ha ving different namespaces

Posted by Vishal Mahajan <Vi...@Sun.COM>.
Yvan,

Please see inline ...

Hess Yvan wrote:

>Hi,
>
>I have a problem to retrieve the Signature element of my signed XML document
>using XPath expression. My document looks like that:
>
><?xml version="1.0" encoding="UTF-8"?>
><edoc:e-document xmlns:dcmi="http://www.imtf.com/e-document/dcmi"
>xmlns:edoc="http://www.imtf.com/e-document"
>xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0">
><ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
>  ....
></ds:Signature>
>   <edoc:metadata>
>      <dcmi:DCMI>
> 
><dcmi:identifier>urn:hypersuite:EFECD0FF-C0A8021C08DEE071-D030940E</dcmi:ide
>ntifier>
>         <dcmi:date>1966-07-20</dcmi:date>
>      </dcmi:DCMI>
>      <edoc:custom>
>         <edoc:customer>333777</edoc:customer>
>         <edoc:account>333777.0</edoc:account>
>         <edoc:account-manager>Giraffe aile</edoc:account-manager>
>         <edoc:amount>123456789.10</edoc:amount>
>         <edoc:type>Savane</edoc:type>
>      </edoc:custom>
>   </edoc:metadata>
></edoc:e-document>
>
>I would like to retrieve my signature element using the XPath expression
>"/edoc:e-document/ds:Signature", but it fails because the namespace "edoc"
>is not known if I use 
>
>Element nscontext = XMLUtils.createDSctx(xmlDocument, "ds",
>Constants.SignatureSpecNS);
>
Also add "edoc" prefix-mapping to nscontext,

    nscontext.setAttributeNS("http://www.w3.org/2000/xmlns/", 
"xmlns:edoc", "http://www.imtf.com/e-document");

Vishal

>sigElement = (Element) XPathAPI.selectSingleNode(xmlDocument,
>signatureLocation, nscontext);
>
>and it fails also if I use 
>
>sigElement = (Element) XPathAPI.selectSingleNode(xmlDocument,
>signatureLocation);
>
>How can I solve the problem (I don't want to use "//ds:Signature") . It seem
>to be a problem of Xalan XPath API....
>
>Thanks for your answer
>
>Yvan
>  
>