PDA

View Full Version : XML Document



hookedOnXML
1 Jun 2007, 6:14 AM
Say I have a document with structure like this:

<order>
<customer>
<name>Customer X</name>
<email>[email protected]</email>
<customer>

<billing>
<address1>Some where</address1>
<address2>#123</address2>
<city>Some City</city>
<zipcode>07896</zipcode>
</billing>

<shipping>
<address1>Right Here</address1>
<address2>#123</address2>
<city>This City</city>
<zipcode>09887</zipcode>
</shipping>

<products>
<product>
<id>1</id>
<sku>ABC123</sku>
<name>ABC Widget</name>
</product>
<product>
<id>2</id>
<sku>DEF123</sku>
<name>DEF Widget</name>
</product>
</products>
</order>


How can I intialize an Order object by reading 'order.xml' so that I can do below:

- Order.get('billing')
- Order.get('shipping')

- Order.get('products')
- Order.get('products').get(0)
- Order.get('products').size()

Further more, Ideally, I should also be able to use this object to make a master-child screen such that you may have a main tab with sub tabs such as Billing, Shipping etc., A grid that shows products ordered. etc.,

I think - This is a pretty common use case for many applications.

Given the generic nature of this use case, it should be fairly easy to create a generic Object which stores the abovementioned data structure - generically?

So each root node (such as customer, billing, shipping, products, product) etc., become, instances of this generic object?

Any thoughts? How does this sounds -

var objOrder = Ext.data.XMLObjectProducer(xmlDocURL); // Bad name perhaps, but.
var objBilling = objOrder.get('billing');
var arrProducts = objOrder.get('products');

for(arrProducts as objProduct){
// do something with objProduct
}

Generic object can provide simple set and get methods. Size methods for collection of objects will be useful.

I am looking for ideas as to how simple xml documents can be read, without learning too much about DomQuery etc.,

Akansha
6 Jun 2007, 4:21 AM
Hi,
did u get any solution about this..actually i am also on the same boat..i dunno hw to parse the XML and use .get('name') method...