Question

Is there a quick way to generate just the 'skeleton' of an xml document? I'm not sure how else to say it, but here is an example of what I need...

Say I had this (probably badly formed) XML document...

<ImATag> 
     <SoAmI>
          *some random data...*
          <OneMore>
               *some more random data...*
          </OneMore>
     </SoAmI>
</ImATag>

And I wanted to return this...

<ImATag> 
     <SoAmI>
          <OneMore>
          </OneMore>
     </SoAmI>
</ImATag>

Is there a fast way of doing it? Program, website, etc? My document is a couple thousand pages, so I can't just go through it manually. I guess I really just want to remove all data within the tags and return just the outline of the document.

Was it helpful?

Solution 4

I ended up just using Oxygen. Does this function for me.

OTHER TIPS

XSLT would do it fairly trivially, of course. (Identity transform plus a transform which says "text nodes produce no output" -- You haven't made clear whether you want to discard attributes, or just attribute content, but that too could be handled easily.)

Or take one of the standard DOM or SAX sample programs which parses and re-serializes XML, and modify it to discard the unwanted text. Probably easier to make that change in the SAX samples.

You need XSL processing.

The following XSLT will copy all nodes except text() nodes:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes"/>
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="text()"/>
</xsl:stylesheet>

You'll need an XSLT processor too, like xsltproc:

xsltproc xsl your-xml

or Java or .NET, or mosth any other framework with an XML parsing library (which usually include XSL transform functions).

Use java and saxparser, handle the DefaultHandler class and write your data in

public void startElement(String namecpaceUri, String localName, String qName, Attributes attrs){}

public void endElement(String namecpaceUri, String localName, String qName){}

where String qName - is all that you need.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top