File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes XMLBeans - Retrieving an attribute and a simple value from the same element Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XMLBeans - Retrieving an attribute and a simple value from the same element" Watch "XMLBeans - Retrieving an attribute and a simple value from the same element" New topic
Author

XMLBeans - Retrieving an attribute and a simple value from the same element

Scott Seto
Greenhorn

Joined: Sep 08, 2011
Posts: 6
Hi,

In my XML, I have:
<internationalPrice currency="EUR">423.46</internationalPrice>

I want to use XMLBeans to retrieve both 'EUR' and '423.46' programmatically.
I looked through the functions that XMLBeans creates and it seems as though I
can only retrieve the currency value and not the 423.46 value.

I used the java.lang.Reflect class in Java to find the functions in the InternationalPriceDocument class
that XMLBeans creates and the InternationalPriceDocument.InternationalPrice class.
None of the functions lets me return the 423.46 value.

Thanks in advance for your help.

Here's the XML schema I am using:

<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:po="http://openuri.org/easypo"
targetNamespace="http://openuri.org/easypo"
elementFormDefault="qualified">

<xs:element name="internationalPrice">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:decimal">
<xs:attribute name="currency" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>

</xs:schema>

Btw, I'm using XMLBeans 2.5
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 464
    
    2
With InternationalPrice being extension of org.apache.xmlbeans.XmlDecimal, you can use the latter's getBigDecimalValue to access to it.
Scott Seto
Greenhorn

Joined: Sep 08, 2011
Posts: 6
Thanks. That works.

Also, if the value is an xmlString instead of xmlDecimal,
you can use the 'getStringValue()' function.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XMLBeans - Retrieving an attribute and a simple value from the same element
 
Similar Threads
need java code for xmlbeans
[XML Schema] same elementname, different attributes
How to create XMl Schema for following
Attribute declaration in XML Schema
jaxb - getting InvocationTargetException during parsing