Hello there,
what exactly is not working for you? When posting questions like this, it is
always helpful to include an error
message, perhaps even a stacktrace. (Also, I might add, it would be considered
good form to sign your mail
by name.)
Your example works for me, here's a test case demonstrating it:
@Test
public void test()
{
HelperContext scope = HelperProvider.getDefaultContext();
DataFactory df = scope.getDataFactory();
DataObject deliverGoods = df.create( "http://dataact.act.org",
"deliverGoods" );
DataObject deliord = df.create( "http://dataact.act.org/xsd",
"DeliverOrder" );
deliord.setDouble( "cost", 100 );
deliverGoods.set( "deliord", deliord );
DataObject sdo = deliverGoods.getDataObject( "deliord" );
double actual = sdo.getDouble( "cost" );
assertEquals( 100, actual, 0.0001 );
double actualXPath = deliverGoods.getDouble( "deliord/cost" );
// <---
assertEquals( 100, actualXPath, 0.0001 );
}
If you're getting a NullPointerException, perhaps you have not instantiated the
"deliord" attribute?
Regards,
Sebastian
----------------- 8< ------------------
Von: grovecai [mailto:[email protected]]
Gesendet: Donnerstag, 28. März 2013 10:16
An: [email protected]
Betreff: About Accessing DataObjects using XPath
Hi,guys
I have a DataObject as below and it's Type is defined in two schema with
different targetNamespace.
Now I want to access the "cost" property of the DataObject.The code is like
that:
DataObject.get("deliord/cost");
It doesn't work. What's proper xpath expression I should use?
Please help. Thanks!
DataObject:
<dat:deliverGoods xmlns:dat="http://dataact.act.org"
xmlns:xsd="http://dataact.act.org/xsd">
<dat:deliord>
<xsd:cost>100</xsd:cost>
<xsd:id>101</xsd:id>
<xsd:address>buaa nmb g513</xsd:address>
<xsd:buyer>cai</xsd:buyer>
<xsd:goodname>The WS Haters Handbook</xsd:goodname>
</dat:deliord>
</dat:deliverGoods>
Schema_1:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ax26="http://dataact.act.org/xsd"
targetNamespace="http://dataact.act.org">
<xs:import namespace="http://dataact.act.org/xsd" />
<xs:element name="deliverGoods">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="deliord" nillable="true"
type="ax26:DeliverOrder" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Schema_2:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://dataact.act.org/xsd">
<xs:complexType name="DeliverOrder">
<xs:sequence>
<xs:element minOccurs="0" name="address" nillable="true"
type="xs:string" />
<xs:element minOccurs="0" name="buyer" nillable="true"
type="xs:string" />
<xs:element minOccurs="0" name="cost" type="xs:double" />
<xs:element minOccurs="0" name="goodname" nillable="true"
type="xs:string" />
<xs:element minOccurs="0" name="id" type="xs:int" />
</xs:sequence>
</xs:complexType>
</xs:schema>
IDS Scheer Consulting GmbH
Geschäftsführer/Managing Directors: Arno Theiss, Ivo Totev
Sitz/Registered office: Altenkesseler Straße 17, 66115 Saarbrücken, Germany -
Registergericht/Commercial register: Saarbrücken HRB 19681
http://www.ids-scheer-consulting.com