• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Scott Seto
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 669
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With InternationalPrice being extension of org.apache.xmlbeans.XmlDecimal, you can use the latter's getBigDecimalValue to access to it.
 
Scott Seto
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. That works.

Also, if the value is an xmlString instead of xmlDecimal,
you can use the 'getStringValue()' function.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic