FlatXmlDataSet and Newline in Data

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

FlatXmlDataSet and Newline in Data

Schröter Daniel
Hi all
 
I was experimenting with DBUnit and run into the following problem:
When I export a table to a FlatXml and then run clean insert all newlines in VARCHAR columns are lost. (Sidenote: If I use the full XmlDataSet the newlines are preserved.) The difference is that the Flat format stores the values in attributes and not in elements. After reading the manuals I expected creating the dtd for the FlatXml would help - but it didnt.
Digging deeper into the problem I found out that the newlines are lost when the FlatXmlProducer reads the Attributes.getValue("attributenameAliasColumname") {and replaces the \n with a space}.
Since the dtd notes the attribute as CDATA and not one of IDREFS,ENTITIES or NMTOKENS I thought that it should be left untouched - my parser thinks different:
 
org.apache.crimson.parser.Parser2.class:937
// For attribute values ...
            if (!isEntityValue) {
                // 3.3.3 says whitespace normalizes to space...
                if (c == ' ' || c == '\t' || c == '\n' || c == '\r') {
                    strTmp.append (' ');
                    continue;
                }


When I searched the net I wondered why no one else seems to have this problem! Please enlighten me!

Regards,
Daniel

 

My ant task:

   <dbunit driver="oracle.jdbc.OracleDriver" url="x" userid="x" password="x"
        schema="s">
        <export dest="propertyentry.dtd" format="dtd">
           <table name="propertyentry"/>
        </export>
    <export dest="propertyentry.xml" format="flat" doctype="propertyentry.dtd">
       <table name="propertyentry"/>
    </export>
   </dbunit>


do something with the data  


   <dbunit driver="oracle.jdbc.OracleDriver" url="x" userid="x" password="x"
        schema="s">
           <operation src="propertyentry.xml" format="flat" type="CLEAN_INSERT" />
    </dbunit>

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user
Reply | Threaded
Open this post in threaded view
|

Re: FlatXmlDataSet and Newline in Data

Schröter Daniel
Hi all

I guess the XmlWriter within DBUnit should be patched with this:

    public XmlWriter writeAttribute(String attr, String value) throws IOException {
        // maintain api
        if (false)
            throw new IOException();
        if (this.attrs == null) {
            this.attrs = new StringBuffer();
        }
        this.attrs.append(" ");
        this.attrs.append(attr);
        this.attrs.append("=\"");
        this.attrs.append(escapeXmlAttribute(value));
        this.attrs.append("\"");
        return this;
    }

    private String escapeXmlAttribute(String value) {
        value = escapeXml(value);
        value = StringUtils.replace(value, "\n", "&#10;");
        value = StringUtils.replace(value, "\r", "&#13;");
        value = StringUtils.replace(value, "\t", "&#9;");
        return value;
    }

In this case the newlines (and tabs and cr's) are correctly escaped even within attributes.

What do you think about this solution?

Regards,
Daniel



-----Ursprüngliche Nachricht-----
Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Schröter Daniel
Gesendet: Freitag, 11. Januar 2008 09:56
An: [hidden email]
Betreff: [dbunit-user] FlatXmlDataSet and Newline in Data

Hi all
 
I was experimenting with DBUnit and run into the following problem:
When I export a table to a FlatXml and then run clean insert all newlines in VARCHAR columns are lost. (Sidenote: If I use the full XmlDataSet the newlines are preserved.) The difference is that the Flat format stores the values in attributes and not in elements. After reading the manuals I expected creating the dtd for the FlatXml would help - but it didnt.
Digging deeper into the problem I found out that the newlines are lost when the FlatXmlProducer reads the Attributes.getValue("attributenameAliasColumname") {and replaces the \n with a space}.
Since the dtd notes the attribute as CDATA and not one of IDREFS,ENTITIES or NMTOKENS I thought that it should be left untouched - my parser thinks different:
 
org.apache.crimson.parser.Parser2.class:937
// For attribute values ...
            if (!isEntityValue) {
                // 3.3.3 says whitespace normalizes to space...
                if (c == ' ' || c == '\t' || c == '\n' || c == '\r') {
                    strTmp.append (' ');
                    continue;
                }


When I searched the net I wondered why no one else seems to have this problem! Please enlighten me!

Regards,
Daniel

 

My ant task:

   <dbunit driver="oracle.jdbc.OracleDriver" url="x" userid="x" password="x"
        schema="s">
        <export dest="propertyentry.dtd" format="dtd">
           <table name="propertyentry"/>
        </export>
    <export dest="propertyentry.xml" format="flat" doctype="propertyentry.dtd">
       <table name="propertyentry"/>
    </export>
   </dbunit>


do something with the data  


   <dbunit driver="oracle.jdbc.OracleDriver" url="x" userid="x" password="x"
        schema="s">
           <operation src="propertyentry.xml" format="flat" type="CLEAN_INSERT" />
    </dbunit>

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user