• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

To delete a sequence in an xml input

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,
I am quite new to XML/DOM, but not so new to java. I have a situation, where the input xml string is being read as a Document and I would like to remove some data(described below) and update the Document with the modified data. Finally the document is converted back to xml string from the Document.
FYI, JDK1.2.2, Xerces parser.
Here is the xml string :
Case1:
<xml....1.0...?>
<fault errCd="1234" errMsg="some msg" errType="E" />
With the above xml string as input, no problem, code works just fine.
Now, consider this xml string:
Case2:
<xml....1.0...?>
<fault errCd="1234" errMsg="some msg" errType="E"
<NVPair name="somename" value="somevalue" />
/>
When the above xml string appears, the code does not work, since it is NOT expecting NVPair, which is a SEQUENCE in the XML structure. Hence I want to delete this sequence (NVpair), so that the xml appears exactly as in case 1 described above.
Any ideas/help will be appreciated.
Thanks in advance.

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear suresh,
You would have known that an XML document contains fully welformed expressions. i.e If you open a tag then it should be closed in a proper way.
In your case u need to obey the following cases
<xml....1.0...?>
<fault errCd="1234" errMsg="some msg" errType="E"/>
<NVPair name="somename" value="somevalue" />
or
<xml....1.0...?>
<fault errCd="1234" errMsg="some msg" errType="E" ></fault>
<NVPair name="somename" value="somevalue"></NVPair>
Hope this will work fine
Best Regards,
Paramaguru.
 
Suresh Ray
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply.
Here is the right xml:
<xml....1.0...?>
<fault errCd="1234" errMsg="some msg" errType="E"/>
<NVPair name="somename" value="somevalue" />
</fault>
Now, like I mentioned earlier in this thread, the problem at hand is that, I have to delete the NVPair tag (and its attributes, name & value) from the xml string and update the Document(DOM) with the modified xml as exactly shown below:
<xml....1.0...?>
<fault errCd="1234" errMsg="some msg" errType="E"/>
</fault>
Any help is appreciated.
Thanks.
 
Suresh Ray
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are there any methods available to update/delete the data in an xml string, in a Document format?
Thanks.
 
Paramagurusamy Balasubramanian
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear suresh,
There are some useful methods found to manipulate your xml document.I suggest you to use dom4j parser or <xtags>.Both are easier and flexible to use.
for dom4j visit http://dom4j.org/cookbook/cookbook.html
for xtags visit http://jakarta.apache.org/taglibs/doc/xtags-doc/intro.html
dom4j provides set of APIs like Document, Element, Node, Branch, XMLReader,XMLWriter etc.,
xtags gives you set of tags,XSLT and XPATH expressions as same as xsl to do different manipulation with xml document..
It is advisable to use any one of the above
Best Regards,
Paramaguru
 
Space pants. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic