Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
So have you looked at using plain old XML::Parser? Just because you find a module called "XML::Simple", this doesn't mean that the fundamental module it's based on (XML::Parser) has to be really complicated -- and in fact it really is not complicated.

Clear your mind of XML::Simple, forget whatever preconceptions have arisen about how you think your code should be written, then read the man page for XML::Parser and see if some different approach becomes clear. You might find that it will be easier to use, and an appropriate algorithm might become self-evident.

(Consider that the man page for XML::Parser is only about one third as long as the one for XML::Simple -- that suggests to me that the latter module may have been misnamed.)

Your goal is not clearly stated here... (Maybe there's a previous thread where you gave more detail?) What needs to be modified? In what sense should the output be in "exactly" the same format, given that changes of some sort need to be made? (I.e. what specific features of the input format need to be preserved?)

And are you sure you need to hold the whole xml stream in a Perl data structure? Are there complicated, hierarchical conditions that are needed to control the mods? Or can the changes be based on relatively localized criteria?

Whatever the task is, XML::Parser will probably be simpler than XML::Simple (which seems to have been tailored to certain types of tasks, and your task might not be among that set).

Other references cited in earlier replies are worth looking at as well -- but I think looking at the fundamental module first would be worthwhile.

update: Sorry, I think I may have misunderstood. You are actually looking for a way to take a bunch of new data (from some non-XML source, like a database or flat file) and push them out in the XML format shown in the example -- is that it? You want a template with placeholders where you can plug in fresh values.

Since you seem to have some repeating elements ("voice_recipient_list" contains one or more "voice_recipients", etc) it's likely that different inputs will have different quantities of these elements. You could try setting up a set of nested templates -- e.g. a template for "voice_recipient" that can be used any number of times to build the "voice_recipient_list", then a template for "voice_broadcast_info" that has a placeholder for the "voice_recipient_list", and so on. But on the whole, it would seem more like you are building up the output from pieces, rather than just tweaking the content of an existing XML stream.


In reply to Re: Operating on XML, or XML::Simple is too simple! by graff
in thread Operating on XML, or XML::Simple is too simple! by jdtoronto

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 admiring the Monastery: (7)
As of 2024-04-19 14:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found