You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by "Saha, Sanjeev" <SS...@asce.org> on 2004/05/18 18:18:47 UTC
Retrieving QName from newInstance()
Requirement
===========
To create an XmlObject pool represented in the form of a HashMap where
the key is the QName and the value is an instance/reference to the
schema XmlObject.
Intention
=========
Given an incoming xml, to simplify the Schema XmlObject look-up based on
the QName of the xml.
Approach
========
Trying to create an instance using, for example, poDoc =
PurchaseOrderDocument.Factory.newInstance(). Although the instance is
created, a quick System.out reveals that the contents are
<xml-fragment></xml-fragment>, which is fine.
However, attempts to use an XmlCursor to retrieve the QName of the
default schema XmlObject returns null:
XmlCursor xc = poDoc.newCursor();
xc.toStartDoc();
xc.toFirstChild() or xc.toFirstContentToken();
xc.getName() returns 'null'
Is there a different approach that needs to be followed to achieve the
required result?
-Sanjeev
-----Original Message-----
From: Eric Vasilik [mailto:ericvas@bea.com]
Sent: Tuesday, May 11, 2004 11:54 AM
To: xmlbeans-user@xml.apache.org
Subject: RE: is it possible to create disjoint xml elements?
It is possible to have individual instances of any type defined by your
schema (global or anonymous). Lets say the type of the name element is
anonymous and you have a global element which defined resume. You could
do something like:
ResumeDocument.Resume.Name.Factory.newInstance();
This will create a lone XmlBean which have the type of the contents of
the name element. Note that the name element itself is not part of this
XmlBean instance. Now, you can save out this instance and you will get:
<xml-fragment>value of the name</xml-fragment>
Because the instance I created above is not well formed (it was just a
piece of text, given that the type of name was not complex, let's say),
the saver synthesizes the xml-fragment element to contain the value.
XmlBeans will strip this element away when it loads it again. Now, if
you don't want the <xml-fragment> element to be saved out, you can use
the XmlOption:
saveSyntheticDocumentElement
to change the name of the document element to be any QName you want. In
your case, you can use "name".
- Eric
> -----Original Message-----
> From: Jonathan A. Chase [mailto:chaseja@muohio.edu]
> Sent: Tuesday, May 11, 2004 6:49 AM
> To: xmlbeans-user@xml.apache.org
> Subject: is it possible to create disjoint xml elements?
>
> Is it possible to create disjoint xml elements with xmlbeans?
>
> That wording probably isn't very clear. Here's an example:
>
> my xml document...
> <resume>
> <name>value</name>
> <address>value</address>
> <resume>
>
> Say my program doesn't care about the <resume> element..it only cares
> about <name> and its child elements. My question is, can I use xml
beans
> to create a <name> object w/o attaching it to a <resume> object in the
> code (even though the xml schema says "a name must belong to a
resume")?
>
> Also, if the above is possible, what's the effect of it when it comes
to
> outputting the elements as text? For instance, if a program wants to
> print only the following:
>
> <name>value</name>
>
> without the surrounding parent elements (as dictated by the schema),
is
> that possible?
>
> Thanks,
> Jon
>
> -
---------------------------------------------------------------------
> To unsubscribe, e-mail: xmlbeans-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
> Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/
- ---------------------------------------------------------------------
To unsubscribe, e-mail: xmlbeans-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/
- ---------------------------------------------------------------------
To unsubscribe, e-mail: xmlbeans-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/