in reply to Reading and Manipulation XML Files

tried the package XML::SIMPLE and I can read out an XML but when I try to read my data by just selection the info I need it wont return a value.

What? Also, your XML isn't valid.

$ perl -MXML::Simple -MDDS -le" Dump( XMLin( shift ))" quat.xml $HASH1 = { JOB => { GROUP => 'xp_maint', NODEID => 'localhost', QUANTITATIVE => [ { NAME => 'QR1-INIT', QUANT => 1 }, { NAME => 'QR2-NODEID', QUANT => 1 }, { NAME => 'QR3-GROUP', QUANT => 1 } ], USE_INSTREAM_JCL => 0 } };
$ cat quat.xml <?xml version='1.0' encoding='ISO-8859-1' ?> <!DOCTYPE DEFJOB SYSTEM "/aa/em/ddd/e62xstf3/resource/defjob.dtd"> <DEFJOB > <JOB GROUP="xp_maint" NODEID="localhost" USE_INSTREAM_JCL="0" > <QUANTITATIVE NAME="QR1-INIT" QUANT="1" /> <QUANTITATIVE NAME="QR2-NODEID" QUANT="1" /> <QUANTITATIVE NAME="QR3-GROUP" QUANT="1" /> </JOB> </DEFJOB> $ perl -MXML::Simple -le " print XMLout( XMLin( shift ), qw! RootName +DEFJOB XMLDecl ! , qq[<?xml version=\x221.0\x22 encoding=\x22ISO-8859 +-1\x22 ?>\n<!DOCTYPE DEFJOB SYSTEM \x22/aa/em/ddd/e62xstf3/resource/d +efjob.dtd\x22>] )" quat.xml <?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE DEFJOB SYSTEM "/aa/em/ddd/e62xstf3/resource/defjob.dtd"> <DEFJOB> <JOB GROUP="xp_maint" NODEID="localhost" USE_INSTREAM_JCL="0"> <QUANTITATIVE NAME="QR1-INIT" QUANT="1" /> <QUANTITATIVE NAME="QR2-NODEID" QUANT="1" /> <QUANTITATIVE NAME="QR3-GROUP" QUANT="1" /> </JOB> </DEFJOB>

1. What would be the best package to use? XML::SIMPLE?

It depends. You can't go wrong with XML::Twig, XML::Rules, XML::LibXML...

I was thinking to read the data into an array, then to see if any "QUANTITATIVE NAME" is used, if not I would create new ones with the GROUP / NODEID

Um, try it and you'll see why its a bad idea, but if you can make it work, or like suffering .... to each his own :)

Replies are listed 'Best First'.
Re^2: Reading and Manipulation XML Files
by gizmojunkee (Novice) on Mar 26, 2010 at 12:06 UTC
    Thanks for your answer, much appreciated. I didn't want to spam the page so I didn't add the entire xml/dtd just a snipe of it. As it still feels somewhat hard to describe my problem technical and on the dot I tried not to over-spam. Now you did say that it is rather a bad idea, what would you suggest how I can solve this sleeker? The aim of this task is to prove a migration script that would read an extract (out.xml) and look for this QuantResources,and complete them depending on there NodeID/Group. Then the System would be able to control the components better. This is for a tool called ControlM. thanks again
      ..so I didn't add the entire xml/dtd just a snipe of it.

      Thats fine, but you could have made it a valid snip, unless the purpose of your post was to troubleshoot your xml (which would be off topic , How (Not) To Ask A Question)

      . Now you did say that it is rather a bad idea, what would you suggest how I can solve this sleeker?

      Like I already said and showed. Using proper parser always beats hand parsing xml.

        Hi, thanks again. It was not my intention to ask something non-Perl related so let me just show you the lot. Basically this is a config dtd of an Automation tool called Control-M. The Jobs which are the automated processes reflect the information in the xml. (Start time, Group-name etc). And this is an extract of 1 application witch is setup in Control-M. Every other App will have the same structure and I need to merge for every single App now the Quantitative Resources which enable me later on in Control-M to stop Job-Groups or an entire Node rather than every single Process. I hope I made a little more sense now? Thanks again