[prev in list] [next in list] [prev in thread] [next in thread] 

List:       xmlbeans-dev
Subject:    SchemaTypeLoader question
From:       Dave Smith <dizzyd () jabber ! org>
Date:       2004-01-29 21:56:43
Message-ID: 4019819B.2030709 () jabber ! org
[Download RAW message or body]

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.


["dynschema-xmlbeans.tar.gz" (application/gzip)]

- ---------------------------------------------------------------------
To unsubscribe, e-mail:   xmlbeans-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-dev-help@xml.apache.org
Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic