aspose file tools*
The moose likes XML and Related Technologies and the fly likes To delete a sequence in an xml input Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "To delete a sequence in an xml input" Watch "To delete a sequence in an xml input" New topic
Author

To delete a sequence in an xml input

Suresh Ray
Ranch Hand

Joined: Feb 21, 2000
Posts: 55
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.

Paramagurusamy Balasubramanian
Ranch Hand

Joined: Aug 17, 2001
Posts: 55
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

Joined: Feb 21, 2000
Posts: 55
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

Joined: Feb 21, 2000
Posts: 55
Are there any methods available to update/delete the data in an xml string, in a Document format?
Thanks.
Paramagurusamy Balasubramanian
Ranch Hand

Joined: Aug 17, 2001
Posts: 55
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
 
wood burning stoves
 
subject: To delete a sequence in an xml input