Title: Message
Steven
 
thanks for an advice. It works, but I thought there's a nicer way to do it. This method makes me jump between object model and cursors, which is inconvinient.
 
thanks,
Argyn
-----Original Message-----
From: Steven Traut [mailto:[EMAIL PROTECTED]
Sent: Monday, May 23, 2005 5:05 PM
To: user@xmlbeans.apache.org
Subject: RE: good way of writing xs:any

Hello Argyn -- This is an area where you have to bypass the JavaBeans-style accessors generated by XMLBeans. Try using an XmlCursor instance to insert the element.
 
So, let's assume your schema defines a <status> element of StatusType that has a <statusdetail> element of type StatusDetailType as a child, and you want to insert a new <statusdetail> child. You might have something like this (er, roughly -- others jump in if I've got it wrong):
 
StatusType status = StatusType.Factory.newInstance();
XmlCursor cursor = status.newCursor();
cursor.toLastAttribute();
cursor.toNextToken();
// Begin a new <statusdetail> element whose namespace URI is the target URI of your schema (let's say http://openuri.org/).
cursor.beginElement("statusdetail", "http://openuri.org/");
// Insert "text of status detail" as an element value.
cursor.insertChars("text of status detail");
cursor.dispose();
 
This should give you something like:
 
<status xmlns="http://openuri.org">
    <statusdetail>text of status detail</statusdetail>
</status>
 
You might search the archives of this mailing list -- this question has been asked a few times, and you may find an answer in one of the other responses.
 
Also, see these topics in the docs for more on the cursor:
 
http://xmlbeans.apache.org/docs/2.0.0/guide/conNavigatingXMLwithCursors.html 
http://xmlbeans.apache.org/documentation/tutorial_getstarted.html (under "Getting Started with the XML Cursor")
http://wiki.apache.org/xmlbeans/XmlBeansTutorial/MixedContent
 
Steve
-----Original Message-----
From: Kuketayev, Argyn (Contractor) [mailto:[EMAIL PROTECTED]
Sent: Monday, May 23, 2005 12:25 PM
To: user@xmlbeans.apache.org
Subject: good way of writing xs:any

Here's a snippet of schema with xs:any element:
 
 <xs:complexType name="StatusDetailType">
  <xs:sequence>
   <xs:any namespace="##any" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
  </xs:sequence>
 </xs:complexType>
XMLBeans generates StatusDetailType without any any children manipulation methods. What's the right way of adding a child element to this element? My child element has Java class generated by XMLBeans too.
 
thanks,
Argyn

Reply via email to