[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

JDOM Modify XML

Posted on 2010-04-02
2
Medium Priority
?
450 Views
Last Modified: 2013-11-18
I have to use the JDOM java api.  Can anyone point me to some examples or let me know how to change the following xml using JDOM?

I have to locate the correct entity (e.g., entity = 50).  If there isn't a value attribute, I have to create a value attribute set to some numeric number.  If there is a value attribute, I have to change its number.
<map>
    <data> 
        <entity id="45" value="234" />
        <entity id="50" />
    </data>
</map>

Open in new window

0
Comment
Question by:lcor
2 Comments
 
LVL 92

Accepted Solution

by:
objects earned 1000 total points
ID: 29492173
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 1000 total points
ID: 29496753
Use XPath. Something like
XPath xPath = XPath.newInstance("/map/data/entity[id='50']");
Element entity = (Element) xPath.selectSingleNode(document);

Open in new window

0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show, step by step, how to integrate R code into a R Sweave document
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

591 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question