• 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

string manipuation

 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All

I am receiving a String content from a method which is a chunk of xml.
The xml is something like this
<parent1>
<child>blahblah</child>
other tags
</parent1>

Or i can recive some thing like this

<parent2>
<child1>blahblah</child1>
other tags
</parent2>


The input xml i recieve will vary dynamically. What i want to do is interspere a fe xml tags just before the closing tag (</parent1> or </parent2> in this case.

Can someone tell me what would be a neat way of doing the same


Regards
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure I follow what you are trying to do. Can you post a before and after example of the XML?
 
Mohit Sinha
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,

Thanks for the response.

Currently I have to write a method which gets a xml payload. We will not be actually using xml parsing & validation here.

So I have to interspere an xml tag inside the xml payload which i receive as input.

So say I have the before xml something like this
****************
<parent1>
<child>blahblah</child>
</parent1>
****************
The after xml should be something like this

****************
<parent1>
<child>blahblah</child>
<newtag>content</newtag>
</parent1>
****************

I have to acheive this via string manipulation.

Regards,
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I recommend some XML framework, it will make the things easier.

Try Jakarta Betwixt (http://jakarta.apache.org/commons/betwixt/)
or Castor (http://www.castor.org/xml-framework.html)

=)
 
author
Posts: 23956
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This can be easily done with regular expressions... Try...



Henry
[ December 20, 2006: Message edited by: Henry Wong ]
 
Mohit Sinha
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Henry,

Thats neat.

If you can just ellaborate what this does it would give us a good understanding on the same.


Thanks & Regards,
 
Henry Wong
author
Posts: 23956
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mohit Sinha:
If you can just ellaborate what this does it would give us a good understanding on the same.

Thanks & Regards,



It just does a regex match on XML -- and capturing it in two groups. For the XML match, it confirms that it must start with a "<tag>" and end with a "</tag>". And that the "tag" that is used is the same, this is done with another group.

Once the match is established, it will insert the new XML between the two captured groups.

Henry
 
It means our mission is in jeapordy! Quick, read this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic