473,569 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML::Simple output issue

4 New Member
Hi,

I'm attempting to create a perl script that will modify a series of RRD databases (a couple hundred of them). in order to do this the RRD database can be exported to XML modified and then restored from XML.

My issue is when using XML::Simple to read in and edit the xml structure and then output it back out the section of XML that was
previously:
Expand|Select|Wrap|Line Numbers
  1. <cdp_prep>                         
  2.    <ds>
  3.       <primary_value>8.2156307858e+03</primary_value>
  4.       <secondary_value>8.2156307858e+03</secondary_value>
  5.       <value> NaN </value>
  6.       <unknown_datapoints> 0 </unknown_datapoints>
  7.    </ds>
  8. </cdp_prep> 
  9.  
becomes:
Expand|Select|Wrap|Line Numbers
  1.  
  2. <cdp_prep>       
  3.    <name>ds</name>       
  4.    <primary_value> 8.2156307858e+03 </primary_value>      
  5.    <secondary_value> 8.2156307858e+03 </secondary_value>
  6.    <unknown_datapoints> 0 </unknown_datapoints>       
  7.    <value> NaN </value>     
  8. </cdp_prep> 
  9.  
the ds tags are no longer there and are instead turned into a new tag called name with a value of ds.

here's a bit of the perl that's doing the altering of the xml files

Expand|Select|Wrap|Line Numbers
  1.  
  2. # read XML file     
  3. my $data = $xml->XMLin("dump.xml");      
  4. $data->{step} = 600;      
  5.  
  6. my @xml;
  7.  
  8. for my $rra ( @{ $data->{rra} } ) { 
  9.    my $lcv=0;         
  10.    my @new;         
  11.  
  12.    for my $value ( @{ $rra->{database}->{row} } ) {
  13.       if($lcv % 2 == 0 || $lcv == 0) {                 
  14.          push(@new, \%$value);                      
  15.       }             
  16.       $lcv++;         
  17.    }             
  18.  
  19.    $rra->{database}->{row} = \@new;             
  20.    push(@xml, $rra);     
  21. }          
  22.  
  23. $data->{rra} = \@xml;     
  24.  
  25. XMLout($data,     OutputFile => $file.".xml",    RootName => 'rrd',  NoAttr => 1);
  26.  
I've been looking around for a while now and don't understand what the problem is. There is however another ds tag higher up in the hierarchy...

Original XML:
Expand|Select|Wrap|Line Numbers
  1.  
  2. <ds>                 
  3.    <name> ds0 </name>                 
  4.    <type> DERIVE </type>                 
  5.    <minimal_heartbeat> 900 </minimal_heartbeat>                 
  6.    <min> 0.0000000000e+00 </min>                 
  7.    <max> NaN </max>               
  8.  
  9.    <!-- PDP Status -->                 
  10.    <last_ds> 1808321630 </last_ds>                 
  11.    <value> 3.3702190024e+06 </value>                 
  12.    <unknown_sec> 0 </unknown_sec>         
  13. </ds>  
  14.  
  15. <!-- Round Robin Archives -->   
  16. <rra>                 
  17.    <cf> AVERAGE </cf>                 
  18.    <pdp_per_row> 1 </pdp_per_row> <!-- 300 seconds -->        
  19.    <params>                 
  20.       <xff> 5.0000000000e-01 </xff>                 
  21.    </params>                
  22.    <cdp_prep>                         
  23.       <ds>                         
  24.          <primary_value> 8.2156307858e+03 </primary_value>
  25.          <secondary_value> 8.2156307858e+03 </secondary_value>
  26.          <value> NaN </value>
  27.          <unknown_datapoints> 0 </unknown_datapoints> 
  28.       </ds>
  29.    </cdp_prep> 
  30.  ... etc
  31.  

I could use any help or suggestions or reading materials anyone could suggest on this.

Thanks
Mar 8 '08 #1
5 2579
jkmyoung
2,057 Recognized Expert Top Contributor
If you rename the ds tag to say dt, would it then work?
It's not a good idea to have multiple ds tags which represent different things unless they're in different namespaces.
Mar 10 '08 #2
0xception
4 New Member
Thanks for the suggestion.... but that also doesn't seem to work. i changed the DS tag to DT and it also gets placed in a tag called NAME...

I wonder if this is a bug in/with XML::Simple perl module... I'm not extremely family with XML so I'm not sure of any best practices or rules but I'm not creating the original XML structure so all i can do is alter it at this point... I'll keep looking but if there are any other suggestions i would be glad to hear them
Mar 10 '08 #3
jkmyoung
2,057 Recognized Expert Top Contributor
Took me several hours to install simpleXML for perl, but found the answer:
Use the KeyAttr parameter to stop this from happening.


XMLout($data, OutputFile => "beer.xml", RootName => 'root', KeyAttr => [], NoAttr => 1);

http://rohan.almeida.in/archives/xml...ons-for-xmlout
Mar 11 '08 #4
0xception
4 New Member
WOW! thanks a LOT... i looked at those config options and didn't think it applied to this so i skipped right over it. sweet!

I still hit another wall (even w/ the correct XML output) the rrd files wont restore but i believe that's an issues to take up with the rrd mailing list because the XML is correct now.

The only difference between the original and the modified XML now is that the modified doesn't have comments and the order of the tags are sorted alphabetically ... i dont see why either of those would cause a problem but i'll talk to them to see if those are the cause (or i'll do some testing myself)


THANKS AGAIN!
Mar 11 '08 #5
0xception
4 New Member
I figured i would update this just in case anyone else was interested. It turns out that the RRD files were element order dependent, and XML::Simple does not preserve the element order...

So long story short i had to scrap the XML::Simple and switch to XML::LibXML which is a bit more complicated to use at first but turns out to work very well.
Mar 12 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

13
2277
by: Paulo Pinto | last post by:
Hi, does anyone know of a Python package that is able to load XML like the XML::Simple Perl package does? For those that don't know it, this package maps the XML file to a dictionary.
8
6487
by: Dan | last post by:
Using XML::Simple in perl is extreemly slow to parse big XML files (can be up to 250M, taking ~1h). How can I increase my performance / reduce my memory usage? Is SAX the way forward?
1
1235
by: jack | last post by:
Hi all, I am working on perl..and am using XML::Simple to parse a xml document. I've been trying to retrieve character data from tags whose occurance is recursive.. The scenario can be better explained as below: For a structure like, <employees> <employee>
0
2121
by: Marv | last post by:
Is it possible to print the path of all leaf nodes of an XML using XML::Simple This is the kind of output text that i'm trying to print (not the leaf node values but the path to reach them) c:\> perl ListLeafs.pl config.xml {RootNode}->{ChildNode1}->{LeafNode1} {RootNode}->{ChildNode1}->{LeafNode2} {RootNode}->{ChildNode1}->{LeafNode3}...
1
3773
by: CDZ | last post by:
This seems simple enough, Read an XML file, output it to the screen. Yes, I know that doesn't make sense but here's why I need it: I have a sharepoint list that I'm viewing the XML from, the URL is LONG and ugly, it comes from a .dll file. Ex:...
0
1409
by: JohnLucas | last post by:
Hi all, I have just started working with the XML::Simple module to parse an XML file. I'm trying to pull some values from the file that I need in another program. The problem is that the XML file is "nested" and I can't get the correct values out of the file. This is part of my xml file: <?xml version="1.0" encoding="ISO-8859-1"?>...
4
3269
by: Steven M. O'Neill | last post by:
I have an xml structure like this: <Meta name="fieldAttributes"> <MetaString name="name">SUB_PHONE</MetaString> <MetaString name="value">999999999</MetaString> </Meta> <Meta name="fieldAttributes"> <MetaString name="name">SUB_NAME</MetaString> <MetaString name="value">XML PLUS</MetaString>
1
2974
by: SM | last post by:
Hello, I have a couple of XML files that represent articles. Each XML file is unique. Meaning that overall the structure is the same but some tags in the xml file are not in the same place or doesn't exist. i.e. <DOC> <title>Book title</title> <p>This is a paragrap</p> <header>Header</header>
2
1827
BeemerBiker
by: BeemerBiker | last post by:
I cannot get the following code to work unless I (1) Change <id> to anything else, or (2) Add an empty section to the bottom of my xml file. Could this be a bug in 5.10.1 ActivePerl or my test xml script is no good? use strict; use warnings; use XML::Simple; use XML::Parser;
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7668
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6281
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5509
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5218
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.