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
Greetings,

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")),
                   XmlObject.Factory.parse(new 
File("xmldsig-core-schema.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();
cur.toFirstChild();

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

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'>
  <myname>abc</myname>
</root>

and end with...

<root xmlns='dizzytest' ds="http://www.w3.org/2000/09/xmldsig#">
  <myname>abc</myname>
  <ds:Signature/>
</root>
       
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.

Thanks,

D.

Mime
View raw message