Flatten XML Document

FGB

Usenet Archive
Joined
Jul 19, 2003
Messages
4
Reaction score
0
Due to the form my instance documents can (sometimes) take, I have a need to flatten my documents from:

Document A
<rootElement>
<element1 value="element1Value">
<element2 value="element2Value">
<element3>element3Text</element3>
</element2>
</element1>
</rootElement>

Document B
<rootElement>
<element3 element1="element1Value"
element2="element2Value">element3Text</element3>
</rootElement>

Bandwidth is one of my primary motivations for this approach, as I anticipate many messages of this type per second. Also all of the data items for Document A are not always available, so the transform from Document A to Document B would be applied in some cases but not in others.

I have searched this group and seen example stylesheets for this type of transform (or similar).

My question is about the the "style" of this approach. In general, does this seem like a reasonable approach to reducing the size of XML documents? By the way, I plan to compress the documents prior to transmission whether Doc. A or Doc. B.

I welcome any comments.

FGB
 

Joris Gillis

Usenet Archive
Joined
Sep 28, 2004
Messages
355
Reaction score
0
Due to the form my instance documents can (sometimes) take, I have a
need to flatten my documents

Hi,

The following stylesheet's output will be similar to your desired output:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:eek:utput method="xml" indent="yes"/>

<xsl:template match="*[text]">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="parent::*" mode="reverse"/> <xsl:apply-templates/> </xsl:copy> </xsl:template>

<xsl:template match="*" mode="reverse">
<xsl:attribute name="{local-name}"><xsl:value-of select="@value"/></xsl:attribute> <xsl:apply-templates select="parent::*[not(self::rootElement)]" mode="reverse"/> </xsl:template>

My question is about the the "style" of this approach. In general, does this seem like a reasonable approach to reducing the size of XML documents? By the way, I plan to compress the documents prior to transmission whether Doc. A or Doc. B.

I don't have experience with XML optimization. Binary-wise, Doc B is a little smaller (but that difference will vanish if you apply zip compression). DOM-wise , I think they absorb the same memory (I could be wrong).

regards,
 
N

Nobody

Due to the form my instance documents can (sometimes) take, I have a need to flatten my documents from:

Document A
<rootElement>
<element1 value="element1Value">
<element2 value="element2Value">
<element3>element3Text</element3>
</element2>
</element1>
</rootElement>

Document B
<rootElement>
<element3 element1="element1Value"
element2="element2Value">element3Text</element3>
</rootElement>

Bandwidth is one of my primary motivations for this approach, as I anticipate many messages of this type per second. Also all of the data items for Document A are not always available, so the transform from Document A to Document B would be applied in some cases but not in others.

I have searched this group and seen example stylesheets for this type of transform (or similar).

My question is about the the "style" of this approach. In general, does this seem like a reasonable approach to reducing the size of XML documents? By the way, I plan to compress the documents prior to transmission whether Doc. A or Doc. B.

I welcome any comments.

FGB
Is starting out with this an option?:
<rootElement>
<element1 value="element1Value"/>
<element2 value="element2Value"/>
<element3>element3Text</element3>
</rootElement>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,208
Messages
3,104,799
Members
249,594
Latest member
henrywalsh

Latest Threads

Top