Hello,
        the size of xml file with commented element (<!-- element></element 
-->) continuously increases when the xmltask writes to it.
At first write it rewrites the < to &lt; and the > to &gt; inside the commented 
elements (<!-- -->)  then at next writes it always changes the & to &amp; , 
which increases the size of xml.
Does anybody observed this behaviour of xmltask? Is it a known issue? Does 
exist some trick to fix it?
You can reproduce the problem with the below provided ANT build.xml, which 
modifies the file.xml.

Thanks, Gabo.

ant -version
Apache Ant(TM) version 1.8.4 compiled on May 22 2012
com.oopsconsultancy.xmltask.version = 1.16

file.xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<element_1 attribute_1="something_1" xsi:noNamespaceSchemaLocation="schema.xsd" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
    <!-- test -->
    <element_2>
        <element_3 attribute_2="something_2"></element_3>
    </element_2>
</element_1>
### end of file.xml

schema.xsd
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema";
attributeFormDefault="unqualified" elementFormDefault="qualified">

<!-- Elements -->
  <xs:element name="element_1">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="element_2" />
      </xs:sequence>
      <xs:attribute name="attribute_1" type="xs:string" use="required" />
    </xs:complexType>
  </xs:element>

        <xs:element name="element_2">
                <xs:complexType>
                        <xs:sequence>
                                <xs:element name="element_3" minOccurs="0" 
maxOccurs="unbounded">
                                        <xs:complexType>
                                                <xs:attribute 
name="attribute_2" type="xs:string" use="required" />
                                        </xs:complexType>
                                </xs:element>
                        </xs:sequence>
                        <xs:sequence>
                                <xs:element name="element_4" minOccurs="0" 
maxOccurs="unbounded">
                                        <xs:complexType>
                                                <xs:attribute 
name="attribute_3" type="xs:string" use="required" />
                                        </xs:complexType>
                                </xs:element>
                        </xs:sequence>
                </xs:complexType>
        </xs:element>

</xs:schema>
###end of schema.xsd

build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project default="main" name="build">
    <taskdef name="xmltask" 
classname="com.oopsconsultancy.xmltask.ant.XmlTask"/>
        <target name="main">

                <loadfile property="file" srcfile="file.xml" />
                <echo message="Not modified 
file.xml:${line.separator}${file}${line.separator}${line.separator}" />

                <echo message="################### 2 ####################" />
                <echo message="Adding new element_4 to file.xml..." />

                <xmltask    source="file.xml"
                    dest="file.xml"
                    encoding="UTF-8"
                    outputter="simple:4" >
            <insert path="/element_1/element_2" xml="&lt;element_4/&gt;"/>
        </xmltask>
                <loadfile property="file2" srcfile="file.xml" />
                <echo message="element_4 in 
file.xml:${line.separator}${file2}${line.separator}${line.separator}" />

                <echo message="################### 2 ####################" />
                <echo message="Now comment element_3 in file.xml..." />
                <replaceregexp file="file.xml" byline="true" 
match="(&lt;)(element_3)" replace="\1!-- \2"/>
                <replaceregexp file="file.xml" byline="true" 
match="(&lt;/element_3)(&gt;)" replace="\1 --\2"/>
                <loadfile property="file3" srcfile="file.xml" />
                <echo message="element_3 commented in 
file.xml:${line.separator}${file3}${line.separator}${line.separator}" />

                <echo message="################### 3 ####################" />
                <echo message="Now add 2nd element_4 to file.xml..." />
                <xmltask    source="file.xml"
                    dest="file.xml"
                    encoding="UTF-8"
                    outputter="simple:4" >
            <insert path="/element_1/element_2" xml="&lt;element_4/&gt;"/>
        </xmltask>
                <loadfile property="file3" srcfile="file.xml" />
                <echo message="2nd element_4 in 
file.xml:${line.separator}${file3}${line.separator}${line.separator}" />

                <echo message="################### 4 ####################" />
                <echo message="Now add 3rd element_4 to file.xml..." />
                <xmltask    source="file.xml"
                    dest="file.xml"
                    encoding="UTF-8"
                    outputter="simple:4" >
            <insert path="/element_1/element_2" xml="&lt;element_4/&gt;"/>
        </xmltask>
                <loadfile property="file4" srcfile="file.xml" />
                <echo message="3rd element_4 in 
file.xml:${line.separator}${file4}${line.separator}${line.separator}" />

                <fail />
                <echo message="################### 5 ####################" />
                <echo message="Now add 4th element_4 to file.xml..." />
                <xmltask    source="file.xml"
                    dest="file.xml"
                    encoding="UTF-8"
                    outputter="simple:4" >
            <insert path="/element_1/element_2" xml="&lt;element_4/&gt;"/>
        </xmltask>
                <loadfile property="file5" srcfile="file.xml" />
                <echo message="4th element_4 in 
file.xml:${line.separator}${file5}${line.separator}${line.separator}" />

        </target>
</project>
####end of build.xml

Output of build.xml:
Buildfile: d:\Work\test3\build.xml

main:
     [echo] Not modified file.xml:
     [echo] <?xml version="1.0" encoding="UTF-8" standalone="no"?>
     [echo]
     [echo] <element_1 attribute_1="something_1" 
xsi:noNamespaceSchemaLocation="schema.xsd" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
     [echo]     <!-- test -->
     [echo]
     [echo]     <element_2>
     [echo]         <element_3 attribute_2="something_2"></element_3>
     [echo]     </element_2>
     [echo] </element_1>
     [echo]
     [echo]
     [echo]
     [echo] ################### 2 ####################
     [echo] Adding new element_4 to file.xml...
     [echo] element_4 in file.xml:
     [echo] <?xml version="1.0" encoding="UTF-8" standalone="no"?>
     [echo]
     [echo] <element_1 attribute_1="something_1" 
xsi:noNamespaceSchemaLocation="schema.xsd" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
     [echo]     <!-- test -->
     [echo]
     [echo]     <element_2>
     [echo]         <element_3 attribute_2="something_2"></element_3>
     [echo]         <element_4></element_4>
     [echo]     </element_2>
     [echo] </element_1>
     [echo]
     [echo]
     [echo]
     [echo] ################### 2 ####################
     [echo] Now comment element_3 in file.xml...
     [echo] element_3 commented in file.xml:
     [echo] <?xml version="1.0" encoding="UTF-8" standalone="no"?>
     [echo]
     [echo] <element_1 attribute_1="something_1" 
xsi:noNamespaceSchemaLocation="schema.xsd" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
     [echo]     <!-- test -->
     [echo]
     [echo]     <element_2>
     [echo]         <!-- element_3 attribute_2="something_2"></element_3 -->
     [echo]         <element_4></element_4>
     [echo]     </element_2>
     [echo] </element_1>
     [echo]
     [echo]
     [echo]
     [echo] ################### 3 ####################
     [echo] Now add 2nd element_4 to file.xml...
     [echo] 2nd element_4 in file.xml:
     [echo] <?xml version="1.0" encoding="UTF-8" standalone="no"?>
     [echo]
     [echo] <element_1 attribute_1="something_1" 
xsi:noNamespaceSchemaLocation="schema.xsd" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
     [echo]     <!-- test -->
     [echo]
     [echo]     <element_2>
     [echo]         <!-- element_3 attribute_2="something_2"></element_3 -->
     [echo]         <element_4></element_4>
     [echo]     </element_2>
     [echo] </element_1>
     [echo]
     [echo]
     [echo]
     [echo] ################### 4 ####################
     [echo] Now add 3rd element_4 to file.xml...
     [echo] 3rd element_4 in file.xml:
     [echo] <?xml version="1.0" encoding="UTF-8" standalone="no"?>
     [echo]
     [echo] <element_1 attribute_1="something_1" 
xsi:noNamespaceSchemaLocation="schema.xsd" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
     [echo]     <!-- test -->
     [echo]
     [echo]     <element_2>
     [echo]         <!-- element_3 
attribute_2="something_2"&amp;gt;&amp;lt;/element_3 -->
     [echo]
     [echo]         <element_4></element_4>
     [echo]         <element_4></element_4>
     [echo]         <element_4></element_4>
     [echo]     </element_2>
     [echo] </element_1>
     [echo]
     [echo]
     [echo]
     [echo] ################### 5 ####################
     [echo] Now add 4th element_4 to file.xml...
     [echo] 4th element_4 in file.xml:
     [echo] <?xml version="1.0" encoding="UTF-8" standalone="no"?>
     [echo]
     [echo] <element_1 attribute_1="something_1" 
xsi:noNamespaceSchemaLocation="schema.xsd" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
     [echo]     <!-- test -->
     [echo]
     [echo]     <element_2>
     [echo]         <!-- element_3 
attribute_2="something_2"&amp;amp;gt;&amp;amp;lt;/element_3 -->
     [echo]
     [echo]         <element_4></element_4>
     [echo]         <element_4></element_4>
     [echo]         <element_4></element_4>
     [echo]         <element_4></element_4>
     [echo]     </element_2>
     [echo] </element_1>
     [echo]
     [echo]
     [echo]

BUILD SUCCESSFUL
Total time: 0 seconds
####end of output of build.xml





------------------------------------------------------------------------------
Flow-based real-time traffic analytics software. Cisco certified tool.
Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer
Customize your own dashboards, set traffic alerts and generate reports.
Network behavioral analysis & security monitoring. All-in-one tool.
http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.clktrk
_______________________________________________
Xmltask-users mailing list
Xmltask-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/xmltask-users

Reply via email to