Rafael wrote:

So I think what you need to do is either use your programatic solution or put the NS definition you are interested in into the dsig-xpath:XPath node itself.


Sorry, but I don't understand the second alternative. Let me explain the scenario in a very short way:


- I have a piece of xml data :
<wrapper><foo:hello xmlns:foo="http://www.foo.com";>world</foo:hello></wrapper>
- Only a part will be signed:
<foo:hello xmlns:foo="http://www.foo.com";>world</foo:hello>
- To "select" that part, we want to use a filter2 xpath 'intersect' with value //foo:hello
- before signing, we want to show to the end user the piece of data that he/she is gonna sign
- That's why we use a piece of code like the one in my first mail to "go through the Document and select it". Input to that code would be the built Document from above bytes plus 'intersect //foo:hello' (in form of a String[][])
- We get then Exception (prefix must ...)
- Our solution forces us to collect all the prefix-ns mappings in a list when building from bytes to Document and use that list to provide every XPath2FilterContainer with extra ns info before adding the latter to the NodeHelperList.


As, while performing those steps, we haven't added a ds:Signature yet, we don't have any dsig-xpath:XPath elements (nodes) in the Document. How can we apply your second option?


Actually you do, they just are not attached to the tree :>. As soon as you create the container, you create the basic DOM nodes that make it up.


So your call to c.setXPathNSPrefix (is that the method?) actually sets the NS attribute on the XPath node. (I.e. I've just realised both my solutions are the same :>).

And note that you *don't* have to know the prefix mapping - just the namespace. You can use a different prefix in your XPath, provided it maps to the namespace you are interested in.

The key thing is that you *must* have the namespace that you are doing XPath searches on "in scope" for the XPath to work - otherwise it simply cannot work out how to resolve a namespace.

Take something like the following :

<nodeA xmlns:a="aargh">
 <a:d xmlns:a="bbrrh"> some data</a:d>
 <a:e xmlns:a="cccrg"> some more data</a:e>
 <Signature>
   ...
   <XPath>Xpath expression that searches something on a:</XPath>
  </Signature>
</nodeA>

The "a" prefix resolves to three separate things. It could resolve to as many things as you want! So the way it works is that in the case above, the XPath will search on namespace "aargh" as that is what is in scope for the XPath transform itself.

But that also means you don't have to know what prefix is used in the doc, only the namespace. So an expression :

<nodeA xmlns:a="aargh">
<a:d xmlns:a="bbrrh"> some data</a:d>
<a:e xmlns:a="cccrg"> some more data</a:e>
<Signature>
...
<XPath xmlns:tosearch="bbrrh">Xpath expression that searches something on tosearch:</XPath>
</Signature>
</nodeA>


will find the "some data" nodes which is what you want.

So I think what you were doing in your original commented out code was correct.

Cheers,
        Berin



Reply via email to