Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / October 2004

Tip: Looking for answers? Try searching our database.

[HELP] Altering XML Document

Thread view: 
Gerorge Reece-Howe - 07 Oct 2004 04:58 GMT
Hi,

If I have an XML Document
<?xml version="1.0" encoding="UTF-8" ?>
<root>
   <node1 />
...
   <nodex nxattr="42" ><![CDATA[My Old Data]]></nodex>
...
   <noden />
</root>

I am able to retrieve a given nodex text and attribute values by using JAXEN
XPath, but how do I edit the nxattr value and nodex text?

Thanks

Gerorge
Gerorge Reece-Howe - 08 Oct 2004 00:27 GMT
> If I have an XML Document
> <?xml version="1.0" encoding="UTF-8" ?>
[quoted text clipped - 8 lines]
> I am able to retrieve a given nodex text and attribute values by using JAXEN
> XPath, but how do I edit the nxattr value and nodex text?

I got this working eventually.
try{
   XPath expression = new DOMXPath("//root/nodex");
   result=(Element) expression.selectSingleNode(xmlDocument);

   //This worked from the outset
   result.setAttribute("nxattr", "newatrrvalue");

   //This didn't work. The output showed the node with an updated attribute
value, but the text unchanged
   //result.setNodeValue("My New Data");

   //This, however, worked just fine
   result.getFirstChild.setNodeValue("My New Data");

   System.out.println(result.toString());
}
catch(JaxenException e){e.printStackTrace;}
catch(DOMException e){e.printStackTrace;}

So when selecting a node, it appears that the Nodes text value is a child of
the node, although the attribute is not.

Gerorge


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.