• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Modifying XML

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,
I have an XML as mentioned below:
<XML1>
<Group1>
<Item11>
<Item12>
</Group1>
<Group2>
<Item21>
<Item22>
</Group2>
......
</XML1>
I have to modify the above XML to as follows:
<XML1>
<Group1&Group2>
<Item11>
<Item12>
<Item21>
<Item22>
</Group1&Group2>
</XML1>
Can any one of u suggest the easiest and the best alternative to do it ?
Thanks & Regards
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kumar
Welcome to the Java Ranch, we hope you�ll enjoy visiting as a regular however,
your name is not in keeping with our naming policy here at the ranch. Please change your display name to an appropriate name as shown in the policy.
Thanks again and we hope to see you around the ranch!!
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Two things:
1) "Group1&Group2" is not a valid name for an XML element because of the ampersand -- you might want to use "Group1-and-Group2" or something like that instead.
2) Do you need to do this in Java or with XSLT? (or are both ok?)
 
Maruthi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am looking for a solution using XSLT. The Groups can be 2 or more, we don't have any control over it and it is generated by the third party application.
My application can parse only one group name and hence we are looking for a solution which transforms the XML using XSLT.
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maruthi,
The naming policy requires both a first name and a last name.
[ February 25, 2004: Message edited by: Lasse Koskela ]
 
author
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should also note that XML1 is not a good name for elements. names beginning with "XML" (in any combination of case) are reserved for use by the W3C.
 
Elliotte Rusty Harold
author
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is possible, but it's very tricky. You'll need to use xsl:call-template and recursion to accumulate the names of all the Group1, Group2, etc. elements into a string variable and then use that as the name of an element created by xsl:element.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic