xom-interest AT lists.ibiblio.org
Subject: XOM API for Processing XML with Java
List archive
- From: "Grzegorz Kaczor" <grzegorz.kaczor AT gmail.com>
- To: "Narjis Malik" <narjismalikster AT gmail.com>
- Cc: xom-interest AT lists.ibiblio.org
- Subject: Re: [XOM-interest] Append in XML file
- Date: Fri, 2 Mar 2007 17:42:09 +0100
Hello,
I think that there is no way to avoid scanning a whole file because
the <service> element can occur anywhere (yes, I know that it cannot
appear anywhere but XOM does not know that :) ). And I do not think
that there are more intelligent ways of modifying XML than read it and
write it back :(.
I think you can replace the node with the following code:
Element el = new Element("synonym");
el.addAttribute(new Attribute("name","ABCDE"));
node.getParent().replaceChild(node, el);
However, I can imagine a simpler way of doing that, without xpath -
XOM allows you to replace the NodeFactory, then when you handle
finishMakingElement you can filter out the elements you wish and
return your element instead of the <service> element. This will for
sure be quicker than xpath. See XOM tutorial page 23.
Hope this helps,
Grzegorz
On 02/03/07, Narjis Malik <narjismalikster AT gmail.com> wrote:
hello,
yes i have parsed the parsed the string using xpath in the same way as u
mentioned but how to replace,
right now i am taking the whole xml document and looking for the element
which i want to append,
then i append and again writing back to the xml file , which is really a
cumbersum job , so i want to know if there is some alternative way of
appending the xml document with out scaning the whole file
, if you know then i can mail u my code.
On 3/2/07, Grzegorz Kaczor <grzegorz.kaczor AT gmail.com> wrote:
> Hello,
>
> did you try parsing the document and then manipulating the resultant
> DOM tree? Just build the document, then run an XPath query (something
> like: //service[@name='GetFuture...'] ) to find all the elements you
> want to replace, after you get the result list, for each node found
> access its parent and replace the found node with a new 'synonym'
> element. This should be straightforward, however I did not implement
> it.
>
> Regards,
> Grzegorz
>
> On 02/03/07, Narjis Malik <narjismalikster AT gmail.com> wrote:
> > Hello,
> >
> >
> > I am working on XML files using nux and xPath, I want to append xml
> > doucument at a particular location, how can I do it....
> >
> > I will demonstrate my question with the following example
> >
> > i have a xml document
> >
___________________________________________________________________________________
> >
> > <?xml version="1.0" encoding="UTF-8"?>
> >
> > <service name="GetFutureSybmolization">
> >
> > <synonym name="bvcvcvc">
> >
> > </synonym>
> >
> > </service>
> >
> >
_____________________________________________________________________________________
> >
> > now what i need , i want to append this xml file with new element :
> >
> > as i scan this xml and when there is service element with name =
> > "GetFutureSybolization"
> >
> > then i want to add new element <synonym name="XYZDGD"></synonym>
> >
> > please help me how can i do it...
> >
> > as i tried to do it but it append at the end of file but i cant append
in
> > some where else
> >
> >
> >
> > waiting for a reply
> > _______________________________________________
> > XOM-interest mailing list
> > XOM-interest AT lists.ibiblio.org
> > http://lists.ibiblio.org/mailman/listinfo/xom-interest
> >
>
>
> --
> "Imagination is more important than knowledge."
> A.E.
>
--
"Imagination is more important than knowledge."
A.E.
-
[XOM-interest] Append in XML file,
Narjis Malik, 03/02/2007
-
Re: [XOM-interest] Append in XML file,
Grzegorz Kaczor, 03/02/2007
-
Message not available
- Re: [XOM-interest] Append in XML file, Grzegorz Kaczor, 03/02/2007
-
Message not available
-
Re: [XOM-interest] Append in XML file,
Grzegorz Kaczor, 03/02/2007
-
Re: [XOM-interest] Append in XML file,
Wolfgang Hoschek, 03/02/2007
- Re: [XOM-interest] Append in XML file, Wolfgang Hoschek, 03/02/2007
Archive powered by MHonArc 2.6.24.