You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by Alex Chen <al...@filemaker.com> on 2014/08/22 19:45:17 UTC
How to keep the order of a node's attributes intact
I am trying to use Xerces C++ to modify an XML file, but somehow the output file does not keep the attributes' order.
I use the sample program, DOMPrint, to see how it reads and writes the XML file. The input files has the following header and nodes:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
....
<rule name="docws" enabled="true" stopProcessing="false">
<action type="Rewrite" url="http://localhost:9090/{R:0}" />
<match url="^docws(/(.*))?" />
</rule>
<rule name="streaming" enabled="true" stopProcessing="false">
<action type="Rewrite" url="http://localhost:9090/{R:0}" />
<match url="^Streaming(/(.*))?" />
<conditions>
<add input="{SERVER_PORT}" pattern="80" />
</conditions>
</rule>
....
</configuration>
The output file becomes
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<configuration>
....
<rule enabled="true" name="docws" stopProcessing="false">
<action type="Rewrite" url="http://localhost:9090/{R:0}"/>
<match url="^docws(/(.*))?"/>
</rule>
<rule enabled="true" name="streaming" stopProcessing="false">
<action type="Rewrite" url="http://localhost:9090/{R:0}"/>
<match url="^Streaming(/(.*))?"/>
<conditions>
<add input="{SERVER_PORT}" pattern="80"/>
</conditions>
</rule>
....
</configuration>
The output file adds a new 'standalone' attribute to the header and changes the order of 'name' and 'enabled' attributes of the 'rule' node.
If I add the setXmlStandalone(true) call to the root document, it does not remove the 'standalone' attribute but only changes it to 'yes'
How can this be fixed?
Thanks.
Alex
----