Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hello Monks.

I am using XML::Simple for xml processing.
I read in following from a file:
<TABLE> <TABLE-CAPTION ID="ID64706055682598"> <LONG-NAME>TABLE NAME</LONG-NAME> </TABLE-CAPTION> <TGROUP COLS="4"> <COLSPEC COLNUM="1" COLNAME="col1" COLWIDTH="1.00*"/> <COLSPEC COLNUM="2" COLNAME="col2" COLWIDTH="1.00*"/> <COLSPEC COLNUM="3" COLNAME="col3" COLWIDTH="1.00*"/> <COLSPEC COLNUM="4" COLNAME="col4" COLWIDTH="1.00*"/> <TBODY> <ROW> <ENTRY COLNAME="col1">A</ENTRY> <ENTRY COLNAME="col2">B</ENTRY> <ENTRY COLNAME="col3">C</ENTRY> <ENTRY COLNAME="col4">D</ENTRY> </ROW> <ROW> <ENTRY COLNAME="col1">E</ENTRY> <ENTRY COLNAME="col2">F</ENTRY> <ENTRY COLNAME="col3">G</ENTRY> <ENTRY COLNAME="col4">H</ENTRY> </ROW> </TBODY> </TGROUP> </TABLE>
And I want to write the same to file. Thing is, that when i am putting the xml to file some values become xml-attributes.
So in the end i got this:
<TABLE> <TABLE-CAPTION ID="ID64706055682598" LONG-NAME="TABLE NAME" /> <TGROUP COLS="4"> <COLSPEC COLNAME="col1" COLNUM="1" COLWIDTH="1.00*" /> <COLSPEC COLNAME="col2" COLNUM="2" COLWIDTH="1.00*" /> <COLSPEC COLNAME="col3" COLNUM="3" COLWIDTH="1.00*" /> <COLSPEC COLNAME="col4" COLNUM="4" COLWIDTH="1.00*" /> <TBODY> <ROW> <ENTRY COLNAME="col1">A</ENTRY> <ENTRY COLNAME="col2">B</ENTRY> <ENTRY COLNAME="col3">C</ENTRY> <ENTRY COLNAME="col4">D</ENTRY> </ROW> <ROW> <ENTRY COLNAME="col1">E</ENTRY> <ENTRY COLNAME="col2">F</ENTRY> <ENTRY COLNAME="col3">G</ENTRY> <ENTRY COLNAME="col4">H</ENTRY> </ROW> </TBODY> </TGROUP> </TABLE>
This read about parameters to XML Simple like VauleAttr and KeyAttr but it seems to have no effect. As far as i have understood i can define with ValueAttr what should be printed as Value and not as Attribute.. Maybe i have misunderstood this API? The same idea i have form KeyAttr so i can define what hash-keys are in the end Attributes and no values..

I am stuck in the middle, any help is highly welcome!
Here my prototype where i read in the an xml-file with the content of the first XML-structure i have put here. By this i can check if (at the end) i will get the same XML-structure back when looking at $xml:

use XML::Simple; use strict; my $xmlParser = new XML::Simple( RootName => 'TABLE', KeepRoot=>1, ValueAttr=>{ 'TABLE-CAPTION' => 'LONG-NAME', }); my $data = $xmlParser->XMLin("testtable.xml"); my $xml = $xmlParser->XMLout($data); print "stop";

Any help is highly welcome!

Regards!
Tobias

In reply to XML::Simple how do i keep the same xml format (Values and Attributs)? by tobias_hofer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2024-04-23 12:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found