xml-xmlbeans-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dave Smith <diz...@jabber.org>
Subject SchemaTypeLoader question
Date Thu, 29 Jan 2004 21:53:55 GMT

I'm in need of some help with the right/correct way to dynamically add 
elements into an XmlObject, which I have a schema for, but no object 
bindings. It seems like the approach I'm using should work, but I wind 
up with an invalid XML document by the time I'm done.

I start off by loading the schema for the XML document I will parsing...

SchemaTypeSystem sts = XmlBeans.compileXsd(
             new XmlObject[]
                   XmlObject.Factory.parse(new File("myschema.xsd")),
             },  XmlBeans.getContextTypeLoader(), null);
SchemaTypeLoader sloader = XmlBeans.typeLoaderUnion(
              new SchemaTypeLoader[]
                    XmlBeans.getContextTypeLoader(), sts
XmlObject doc = sloader.parse(new File("test1.xml"), null, null);

The XmlObject I get back is a valid (i.e. doc.validate() returns true). 
So, to this point, I think I'm doing stuff the right way. Now, I want to 
add in a digital signature to this document...

XmlCursor cur = doc.newCursor();

XmlComplexContentImpl req_impl = (XmlComplexContentImpl)cur.getObject();
QName qn = new QName("http://www.w3.org/2000/09/xmldsig#", "Signature");

I took this approach of casting to XmlComplexContentImpl from some scomp 
generated files. From the debugging tracing I've done so far, the 
add_element_user() method SHOULD take into account the schema of the 
underlying XmlObject when inserting a new element. However, it doesn't 
appear to be working for me. Specifically, I start with this...

<root xmlns='dizzytest'>

and end with...

<root xmlns='dizzytest' ds="http://www.w3.org/2000/09/xmldsig#">
So my document is now invalid, since the Signature element is in the 
wrong place. Any suggestions?

I appreciate any guidance that can be spared. My monitor is starting to 
get a dent in it from banging my head against it for the past 3 days. :) 
I'm attaching a tar.gz file the class, schema, and sample XML file.



View raw message