Hello, I resolved my problem!! =)
 
I used the static method getElementById of the IdResolver class 
 
i had to do the following import
 
import org.apache.xml.security.utils.*;
 
So now i can get and Element using the id as input, given the fact that the xml 
has no schema associated.... =)
 
hope that the getElementById method  is efficient ahah 
 
Thanks again 
 
 
Francisco
 



From: [EMAIL PROTECTED]: [EMAIL PROTECTED]: problem DOMSignContext 
getElementByID org.w3c.dom.DocumentDate: Thu, 17 Jan 2008 21:03:56 +0000


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! MSN Messenger 
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

Reply via email to