xml-simple

Parse XML data and append a new element using XML::Simple

不打扰是莪最后的温柔 提交于 2019-12-25 18:26:24
问题 I'm using XML::Simple and XML::Dumper. I'm well aware of the issues surrounding the former module. If I could use an alternative library, I would. What I want to achieve is to load the XML, then append lines to it. This is my XML structure before the script has run. <person> <appearance> <param name="height" value="6,3"/> </appearence> </person> The script, or what I intended to code, should load this XML from a file, then append a <param> element onto <appearence> . I've attempted it using

How do I encode key-value pairs using Perl's XML::Simple module?

一曲冷凌霜 提交于 2019-12-13 04:12:37
问题 I have a hash of the form my $hash = { 'Key' => "ID1", 'Value' => "SomeProcess" }; I need to convert this to an XML fragment of the form <Parameter key="ID1">Some Process a</Parameter> <Parameter key="ID2">Some Process b</Parameter> <Parameter key="ID3">Some Process c</Parameter> How can this be done? 回答1: First of all, your sample is not a valid XML document , so XML::Simple takes a little jury-rigging in order to output it. It seems to expect to output documents , not so much fragments. But

Parsing a XML file with Perl XMLSimple

为君一笑 提交于 2019-12-11 23:29:55
问题 I'm trying to parse a XML -like file with the following structure: Edit: I tried to omit most of the huge xml file to simplify everything but c/p-ed wrongly. Here's the full file (900kb!) that actually has this issue: https://docs.google.com/file/d/0B3ustNI1qZh1UURrYWZJQk0wVlU/edit?usp=sharing <CIM CIMVERSION="2.0" DTDVERSION="2.0"> <DECLARATION> <DECLGROUP> <LOCALNAMESPACEPATH> <NAMESPACE NAME="signalingsystem"/> </LOCALNAMESPACEPATH> <VALUE.OBJECT> <INSTANCE CLASSNAME="SharedGtTranslator">

How to parse multi record XML file ues XML::Simple in Perl

拈花ヽ惹草 提交于 2019-12-11 07:19:28
问题 My data.xml <?xml version="1.0" encoding="ISO-8859-1"?> <catalog> <cd country="UK"> <title>Hide your heart</title> <artist>Bonnie Tyler</artist> <price>10.0</price> </cd> <cd country="CHN"> <title>Greatest Hits</title> <artist>Dolly Parton</artist> <price>9.99</price> </cd> <cd country="USA"> <title>Hello</title> <artist>Say Hello</artist> <price>0001</price> </cd> </catalog> my test.pl #!/usr/bin/perl # use module use XML::Simple; use Data::Dumper; # create object $xml = new XML::Simple; #

XML::Simple encoding problem

风格不统一 提交于 2019-12-11 06:45:51
问题 I have an xml-file I want to parse: <?xml version="1.0" encoding="UTF-8" ?> <tag>û</tag> It's perfectly parsed by firefox. But XML::Simple corrupts some data. I have a perl-program like this: my $content = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"; $content .= "<tag>\x{c3}\x{bb}</tag>\n"; print "input:\n$content\n"; my $xml = new XML::Simple; my $data = $xml->XMLin($content, KeepRoot => 1); print "data:\n"; print Dumper $data; and get: input: <?xml version="1.0" encoding="UTF-8" ?> <tag

perl, parsing XML using XML::Simple

无人久伴 提交于 2019-12-11 03:34:44
问题 I'm doing something wrong when parsing XML. Somehow I has to iterate two loops, where only one should be needed. What am I doing wrong here? First the xml data: <fishy> <fish displayName = "Scalar" description = "the first fish I bought." /> <fish displayName = "crystal red" description = "not really a fish." /> </fishy> Then my perl code: #!/usr/bin/perl -w use strict; use XML::Simple; use Data::Dumper; #Read configuration my $simple = XML::Simple->new(); my $data = $simple->XMLin('test.xml'

Android, help with a simpleframework PersistenceException

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-08 00:58:47
问题 I am trying to use org.simpleframework.xml . classes to handle xml data on my Android project. I can't understand how to build my class "Point" contructor to match the xml definition: at run-time I get this exception: org.simpleframework.xml.core.PersistenceException: Constructor not matched for class koine.marcos.wifidemo.Point My xml data is like this: File points.xml: <?xml version="1.0" encoding="utf-8"?> <points> <point id="La Gioconda"> <rssi ssid="beacon1" bssid="00:21:91:d1:36:62">-52

Android, help with a simpleframework PersistenceException

旧时模样 提交于 2019-12-06 07:22:55
I am trying to use org.simpleframework.xml . classes to handle xml data on my Android project. I can't understand how to build my class "Point" contructor to match the xml definition: at run-time I get this exception: org.simpleframework.xml.core.PersistenceException: Constructor not matched for class koine.marcos.wifidemo.Point My xml data is like this: File points.xml: <?xml version="1.0" encoding="utf-8"?> <points> <point id="La Gioconda"> <rssi ssid="beacon1" bssid="00:21:91:d1:36:62">-52</rssi> <rssi ssid="beacon2" bssid="00:12:a9:03:23:32">-97</rssi> </point> <point id="La Pietà"> <rssi

Change an XML file content via Perl script

爷,独闯天下 提交于 2019-12-01 09:59:02
问题 This thread is in continuation of Perl script to populate an XML file . The file I want to change is: <?xml version="1.0" encoding="UTF-8"?> <configuration start="earth"> <country-list> <country name="japan"> <description></description> <start>1900</start> <end/> </country> <country name="italy"> <description></description> <start>1950</start> <end/> </country> <country name="korea"> <description></description> <start>1800</start> <end/> </country> </country-list> </configuration> I want to

Perl code for Find and replace a tag value in XML

≡放荡痞女 提交于 2019-12-01 05:35:49
问题 Below is the XML I will be using: <a> <id>ABC</id> <class /> <gender /> </a> I want to write a Perl code which search for tag 'id' and replace the value "ABC" with "DEF". However the nesting of above XML can change. So I want to make a generalized code that search for the tag 'id' independently of its exact position. Till now i am able to get the logic where i can replace the value in ABC but that makes my code static of the position of tag 'id'. #!usr/bin/perl use warnings; use XML::Simple;