You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by Radu Preotiuc-Pietro <ra...@bea.com> on 2005/08/03 20:43:28 UTC

RE: Keeping track of where element was in XML

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: novotech@ntlworld.com [mailto:novotech@ntlworld.com]
Sent: Saturday, July 30, 2005 6:37 PM
To: user@xmlbeans.apache.org
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: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org