aspose file tools*
The moose likes XML and Related Technologies and the fly likes compare text contents of xml element and add child element to a particular node in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "compare text contents of xml element and add child element to a particular node in Java" Watch "compare text contents of xml element and add child element to a particular node in Java" New topic
Author

compare text contents of xml element and add child element to a particular node in Java

sarah sainy
Greenhorn

Joined: Oct 18, 2013
Posts: 23
i have an arraylist which contains title and fullname in the following format



First i am splitting the contents with |.I will get the title and fullnames. Then i split fullnames with space to get firstname and familyname.

Now i have 3 strings



The next task is i have check the text contents of existed xml with the above strings firstname and familyname.Here is the existed xml



if the
firstname
and
familyname
contets matches with the text content of above xml elements
<firstname>,<familyname>
then
i have to create on element named
<title>
and append the corresponding title from my list.

I have tried with the following code,




How to get the children and check for text contents?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38405
    
  23
Sounds too difficult for us who are “beginning”, so I shall try moving it to our XML forum.

I think you are parsing the contents of the list correctly, so you need to parse the XML. Are the entries in the List and the XML in the same order? Why do you have the data in those two places in the first place?
Ravi Khadgi
Greenhorn

Joined: Aug 06, 2010
Posts: 20

Following APIs should helpful:

- Create a new node
Document.createElement

- Create a text node
Document.createTextNode

- Insert a node inside another node
Node.appendChild
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: compare text contents of xml element and add child element to a particular node in Java