santuario-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Francisco Sepulveda <shepu_2...@hotmail.com>
Subject problem DOMSignContext getElementByID org.w3c.dom.Document
Date Thu, 17 Jan 2008 21:03:56 GMT

Hello everyone ... 
 
I want to sign the following xml file ENVELOPED with respect to the element with id "a2"
 
         <?xml version="1.0"?>
         <getToken>
              <contexto id="trx">
                   <monto>100</monto>
              </contexto>
 
              <item id="a2">
                   <semilla>10</semilla>
              </item>
 
              <item id="a3">
                   <semilla>11</semilla>
              </item>
          </getToken>
As you can see there is no namespace declaration for the XML file...
 
The output should be:
 

         <?xml version="1.0"?>
         <getToken>
              <contexto id="trx">
                   <monto>100</monto>
              </contexto>
 
              <item id="a2">
                   <semilla>10</semilla>
                   <Signature>... </Signature>
              </item>
 
              <item id="a3">
                   <semilla>11</semilla>
              </item>
          </getToken>
I know that i have to specify the place of the signature were you create an instance of the

DOMSignContext class...
 
I GET WHAT I WANT IF I DO ...
 
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
 
doc = dbf.newDocumentBuilder().parse(new FileInputStream("file.xml"));
 
Element e=(Element)doc.getElementsByTagNameNS(null, "item").item(0);
dsc = new DOMSignContext(pk,e );
 
BUT the problem is that for that i will have to know the "NAME" of the element and its "POSITION"
in the document for the case when the tag appers more than once... 
 
So, it would be better to be able to do this....
 
  
Element e=(Element)doc.getElementsByID("a2");
dsc = new DOMSignContext(pk,e );
 
But when i do that i get 
 
Exception in thread "main" java.lang.NullPointerException: parent cannot be null
 
 
I know that you can register the ID attribute as a valid ID type using the setIdAttributeNS
method of the DomSignContext class, but my problem is that given the structure of the Document
class and its public methods i have to create an instance of the class first, when i create
the instance i have to do
 
dsc = new DOMSignContext(pk,e );
 
And after that i could do 
 
dsc.setIdAttributeNS(e, null, "id");
 
and it suppose that after that the id attribute of the e element is registered???
 
but at that time i already have the element that i was looking for =(
 
Hope you get it, but i want to obtain the element given its ID, and the source xml doen't
have an schema associated to it... is the ONLY WAY to obtain the element given the id is to
use the getElementsByTagNameNS method or i can use directly the getElementsByID method directly??
in that case HOw do you do that without obtaining the "parent can not be null exception" ??
 
Thanks you very much for reading the email
 
Francisco
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
Mime
View raw message