santuario-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Raul Benito <raul.benito.gar...@gmail.com>
Subject Re: ElementProxy troubles
Date Mon, 28 Feb 2005 22:32:39 GMT
It took me awhile but i cought it:
You have a relative namespace and the c14n fails when trying to render
the relative.
Fix the relative, or use serializer that will be better. At least you
want it c14n so use directly the c14n api.
The XMLUtils.outputDOM is one of the API methods I want to get rid
off, there are a lot of them that are not tested enough, not used in
the code, but perhaps are used by some people in their programs.
Perhaps we can have more luck when we adopt JSR 105 API and only
expose the interface.

Regards,

Raul,

p.s- below you can see an example of XMLSerializer.

On Mon, 28 Feb 2005 11:16:54 +0100, Kenneth Jensen <xmlsec@gmail.com> wrote:
> Hi guys,
> 
> I'm working on some XKMS stuff, and thought I could reuse the
> ElementProxy class from org.apache.xml.security.utils package. The
> thing is, it doesn't do as I expect it to, so I'm inclined to just
> hack up my own version.
> 
> The addTextElement( String text, String localname) doesn't append the
> new element to the tree, and I don't really see why, so if anyone
> could enlighten me please. :)
> 
> Below is a code example to illustrate my question, and I use the
> xml-security code from CVS (from some day in last week). The output I
> expect is something like this:
> 
> <myrootelement xmlns="mynamespace">
>   <mytextelement xmlns="http://w3.org/xml-dsig/...">
>       sometext
>   </mytextelement>
> </myrootelement>
> 
> -but the actual output is:
> 
> <myrootelement></myrootelement>.
> 
> I've been staring at it for some time, so I hope I'm not missing
> something obvious.
> 
> --
> ---
> Cheers,
> Kenneth
> 
> ====
> import org.apache.xml.security.utils.*;
> import org.w3c.dom.*;
> import org.apache.xerces.dom.*;
> 
> public class MyElementProxyTester {
> 
>         public static void main(String[] args) throws Exception {
>         org.apache.xml.security.Init.init();
> 
>         // get DOM implementation and create a new document object
>             DOMImplementation builder = DOMImplementationImpl.getDOMImplementation();
>             Document doc = builder.createDocument( "mynamespace",
> "myrootelement", null  );
> 
>         // make an ElementProxy for the document
>         ElementProxy ep = new MyElementProxy( doc );
> 
>         // add a text element to the element through the ElementProxy
>         ep.addTextElement("sometext", "mytextelement" );
> 
>         // check if it works
>         XMLUtils.outputDOM( ep.getDocument().getDocumentElement(), System.out );
                  XMLSerializer xs=new XMLSerializer();
		   xs.setOutputByteStream(System.out);
		   xs.serialize(ep.getElement());
>         }
> }
> 
> class MyElementProxy extends ElementProxy {
> 
>     public MyElementProxy( Document doc ){
>         super( doc);
>     }
> 
>     public String getBaseLocalName(){
>         return "mylocalname";
>     }
>     public String getBaseNamespace(){
>         return "mynamespace";
>     }
> }
> ======
> 


-- 
http://r-bg.com

Mime
View raw message