From: "Minal Ashar" <[EMAIL PROTECTED]>
> Hi,
>
> Thanks for the hint.Here is where my actual problem lies.
>
> I have a GUI ,which is dynamically generated by reading my xsd for its
basic
> structure as to what all tags my xml file can accept and taking the values
> from the existing xml file.Now when i want to add a node to the xml file
> from the gui,it should go and append the tag in the xml according to the
> structure in the Schema.
>
>
> I know the parent of the newly added node.
>
> I am able to read the schema file for the structure of the parent,because
it
> is within this node that I need to add the child.
>
> I dont have the exact position that I know where the node has to go to.
>
> Here is the sample.This is my schema.
> <Record>
> <Bookcode/>
> <Author/>
> <Price/>
> </Record>
>
> The xml file says
> <Record>
> <Bookcode>001</Bookcode>
> <Price>50</Price>
> </Record>
> Another case of xml could be
> <Record>
> <Bookcode>001</Bookcode>
> <Author>aaa</Author>
> <Price>50</Price>
> </Record>
>
>
> I add a new Author tag in my gui.
>
> Currently it goes and it adds itself after <Price> which is invalid.
>
> This is where I am facing trouble.
>
> Could u help??


You could always make an order-independant schema, then you won't have any
ordering problems. Thats probably the easiest way around the problem.

Other than that, you need to somehow parse your schema into a structure that
you can use to know the correct place to add your new elements to. There's
no feature in dom4j to do this automatically for you.

You could try implementing your own special RecordElement (using your above
example) such that when elements are added, they are automagically added to
the correct place in the list. So adding an <Author> tag would go after the
<Bookcode> but before <Price> (say).

James
-------
http://radio.weblogs.com/0112098/

>
> Thanks,
> Minal
>
>
>
>
>
> -----Original Message-----
> From: James Strachan [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, September 11, 2002 2:51 PM
> To: Minal Ashar; [EMAIL PROTECTED]
> Subject: Re: Xml Restructuring
>
>
> From: "Minal Ashar" <[EMAIL PROTECTED]>
> > Hi James,
> >
> >
> > I am currently using your dom4j parser to parse my xml documents.I am
> facing
> > a slight difficulty in trying to achieve the following output.
> >
> >
> > I have an xml file which conforms to a schema.I have an application
which
> is
> > a frontend to view my xml and make additions to or delete from the xml
> file.
> >
> > When I try to update my xml document with the new tag and its values,the
> tag
> > appends itself as the last child of its parent.
> > My requirement is to position the tag within its parent so that it
> validates
> > against the schema.
> >
> > Would appreciate an insight into how would I do this using dom4j.
> >
> > Regards,
> >
> > Minal Ashar
>
> Element.content() (and Element.elements())) returns a List which can be
> manipulated directly using the standard List interface. Changes to the
List
> will be reflected in the document. So you could add an element, then move
it
> to the correct position. Or just create a new element then add it at the
> correct index via List.set(int, node);
>
> DocumentFactory factory = new DocumentFactory();
> Element foo = ...;
>
> Element bar = factory.createElement( "new" );
> // add bar at a specific index
> foo.content().add(2, bar);
>
> James
> -------
> http://radio.weblogs.com/0112098/
>
> __________________________________________________
> Do You Yahoo!?
> Everything you'll ever need on one web page
> from News and Sport to Email and Music Charts
> http://uk.my.yahoo.com
>



__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com


-------------------------------------------------------
In remembrance
www.osdn.com/911/
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to