Reputation: 5285
I have a xml doc as below.
<data>
<employee>
<moretag> may or may not contain inner tag and attributes</moretag>
<somemore> may contain inner tags</somemore>
</employee>
</data>
i want op as below
<employee>
<moretag> may or may not contain inner tag and attributes</moretag>
<somemore> may contain inner tags</somemore>
</employee>
That is i want to strip off data tags
.How can i do it?
Upvotes: 0
Views: 148
Reputation: 1179
Do it with XSLT
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="data">
<xsl:copy-of select="child::node()" />
</xsl:template>
</xsl:stylesheet>
Upvotes: 1
Reputation: 2447
You cannot simply strip off some node like that.
The simple logic of what you tend to achieve is that you make a copy of firstChild of root node i.e. and replace the root node with it.
P.S. that you have only one child under the root node.
Upvotes: 0
Reputation: 6656
You can use jdom
for this:
InputStream is = new FileInputStream(xmlFileName);
InputStreamReader isr = new InputStreamReader(is, "UTF-8");
Document doc = new SAXBuilder().build(isr);
Element data = doc.getRootElement();
Element employee = data.getChild("employee");
XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat());
xmlOut.output(employee, System.out);
Upvotes: 1