Hi Steven,

This is one area where the functionality of xmlbeans is limited

Assume statusDetail is a complex element, in that case it is very
difficult to insert the object. Idealy it would make life simpler if
xmlcustor had
        insertXMLObject() besides insertChars().
  
Eg:
 <status xmlns="http://openuri.org";>
    <statusdetail>
                <s1>
                   <s2>text of status detail</s2>
              </s1>
    </statusDetail>
</status>

Though it can be done via xmlcursor , it is not trivial to create the
above xml fragment if status is  defiend to have xsd:any.

Regards,
Haneef


________________________________

From: Steven Traut [mailto:[EMAIL PROTECTED] 
Sent: Monday, May 23, 2005 2: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


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to