Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re^2: Formatting in XML::Twig->print()

by mirod (Canon)
on Feb 12, 2005 at 17:12 UTC ( #430436=note: print w/replies, xml ) Need Help??

in reply to Re: Formatting in XML::Twig->print()
in thread Formatting in XML::Twig->print()

my $parser = new XML::Twig(KeepSpaces => 'true', ErrorContext => 2);

No more mystery: KeepSpaces essentially tells XML::Twig to keep its hands off of whitespace management. So if you want your elements to be indented, you will have to do it yourself, by inserting an element containing the appropriate whitespace between the 2 Server elements. Or you could probably remove the KeepSpaces option alltogether. Is there any reason why it's there?

Replies are listed 'Best First'.
Re^3: Formatting in XML::Twig->print()
by Nitrox (Chaplain) on Feb 12, 2005 at 19:28 UTC
    Without the KeepSpaces option, XML::Twig munges all the whitespace in the original XML so that the output looks like:
    <Config ASDisableNagle="false" AcceptAllContent="false" IISDisableNagl +e="false" IgnoreDNSFailures="false" RefreshInterval="60" ResponseChun +kSize="64"><Log LogLevel="Error" Name="/opt/IBMWebAS/logs/native.log" +/><VirtualHostGroup Name="foobarcom"><VirtualHost Name=""/ +></VirtualHostGroup><ServerCluster CloneSeparatorChange="false" LoadB +alance="Round Robin" Name="cl_app302_prod" PostSizeLimit="-1" RemoveS +pecialHeaders="true" RetryInterval="60"><Server CloneID="umjbf6mv" Co +nnectTimeout="0" ExtendedHandshake="false" LoadBalanceWeight="2" MaxC +onnections="-1" Name="swel3p_cl_app302_prod" WaitForContinue="false"> +<Transport Hostname="" Port="8132" Protocol="http"/></S +erver><PrimaryServers><Server Name="New_2"/><Server Name="New_1"/></P +rimaryServers></ServerCluster> <!-- APP URI groups point at urls --> <UriGroup Name="event/event.war_URIs"><Uri AffinityCookie="JSESSIO +NID_302" Name="/event/*.jsp"/><Uri AffinityCookie="JSESSIONID_302" Na +me="/event/ThreadedEventServlet"/></UriGroup> <!-- Route statement bring it all together --> <Route ServerCluster="cl_app302_prod" UriGroup="event/event.war_URI +s" VirtualHostGroup="foobarcom"/></Config>

      Indeed, but did you try using the pretty_print => 'indented' option too?

        Perfect! That is the combination I was looking for.

        One other minor issue; the Encoding declaration line, <?xml version="1.0" encoding="ISO-8859-1"?>, from the original input file doesn't get written to the output file. Is this another setting I overlooked or do I need to simply print that manually before printing the XML?

        Thanks for all your help.


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://430436]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2023-05-29 14:29 GMT
Find Nodes?
    Voting Booth?

    No recent polls found