Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
sarah sainy
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48404
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Following APIs should helpful:

- Create a new node
Document.createElement

- Create a text node
Document.createTextNode

- Insert a node inside another node
Node.appendChild
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic