| 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: 357
|
|
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.
|
 |
 |
|
|
subject: XMLBeans - Retrieving an attribute and a simple value from the same element
|
|
|