This is exactly what XmlCursors are for!
Say you have a "car" object and an "engine" object.
You can do
    switch (car.newCursor().comparePosition(engine.newCursor()))
    {
    case -1: // car comes before engine
    case  1: // car comes after engine
    }

Or, you can do:
    XmlCursor c = parent.newCursor().toFirstChild();
    SchemaType t = c.getObject().schemaType();
    if (t == Car.type) { } // the first element was a car
    else if (t == Engine.type) { } the first element was an engine
    else ...

(take a look at the OrderMatters sample from XmlBeans site)

And finally, all the Java classes that we generate mirror the class derivation 
hierarchy from your Schema which most of times is the most convenient way of 
using polymorphism, because it matches the intent of the Schema author and 
matches valid input documents. Also, all Java classes extend XmlObject if you 
want to deal with it this way instead. And we have a feature that allows you to 
add functionality to generated XmlBeans classes, see the "Extensions feature" 
in the news section of the site.

So you do have a number of options, and judging by what your needs are, it 
sounds like XmlBeans would fit the bill nicely.

Radu

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Saturday, July 30, 2005 6:37 PM
To: [email protected]
Subject: Keeping track of where element was in XML


Hi,

Fir me - its important to know the order that the elements were seen in the 
XML document.  For example I have a schema which allows cars, wheels, 
engines in any order, inside a car object (say).  Firstly I need a way of 
telling 
XMLBeans tht all generated java code should extend a particualr object so i 
can deal with the objects poplymorphically.

Second and more importantly I need a way of knowing that a wheel was the 
first element in the xml document, and that the car was the second.  This is 
not availabloe.

Please help

-----------------------------------------
Email sent from http://www.ntlworld.com/
Virus-checked using McAfee(R) Software 
Visit www.ntlworld.com/security for more information


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to