You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xmlbeans.apache.org by Cezar Andrei <ce...@bea.com> on 2004/02/03 20:48:09 UTC

RE: SchemaTypeLoader question

Dave,

My guess is that the cursor is not in the right position, but the right approach for what you're trying to do is to just use the XmlCursor API.

Cezar

> -----Original Message-----
> From: Dave Smith [mailto:dizzyd@jabber.org]
> Sent: Thursday, January 29, 2004 3:57 PM
> To: xmlbeans-dev@xml.apache.org
> Subject: SchemaTypeLoader question
> 
> 
> 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.
> 
> 

- ---------------------------------------------------------------------
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/


Re: SchemaTypeLoader question

Posted by Dave Smith <di...@jabber.org>.
Cezar Andrei wrote:

>Dave,
>
>My guess is that the cursor is not in the right position, but the right approach for what you're trying to do is to just use the XmlCursor API.
>  
>
I don't quite follow this -- how do I know where to position the cursor 
to begin my insert of a new element (according to the underlying schema)?

I did figure out a workaround -- I calculated the QNameSet for the value 
I needed to insert dynamically such that the add_element_user() had 
sufficient information to do the insert. The cool thing is that once the 
underlying SchemaType was updated with the QNameSet information, 
add_element_user() could be called any number of times (on that 
particular element) with the right behaviour.

D.



- ---------------------------------------------------------------------
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/


Re: SchemaTypeLoader question

Posted by Dave Smith <di...@jabber.org>.
Cezar Andrei wrote:

>Dave,
>
>My guess is that the cursor is not in the right position, but the right approach for what you're trying to do is to just use the XmlCursor API.
>  
>
I don't quite follow this -- how do I know where to position the cursor 
to begin my insert of a new element (according to the underlying schema)?

I did figure out a workaround -- I calculated the QNameSet for the value 
I needed to insert dynamically such that the add_element_user() had 
sufficient information to do the insert. The cool thing is that once the 
underlying SchemaType was updated with the QNameSet information, 
add_element_user() could be called any number of times (on that 
particular element) with the right behaviour.

D.



- ---------------------------------------------------------------------
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/