xml-twig

How do I add child elements to XML using Perl's XML::Twig?

寵の児 提交于 2019-12-06 05:27:10
I have the following XML file: <SOURCE_SERVER> <SERVER HOSTNAME="serv1"> <CIFS_SERVICE NETBIOSNAME="serv1"/> </SERVER> <SERVER HOSTNAME="serv2"> </SERVER> <SOURCE_SERVER> Now, I want to add child <CIFS_SERVICE NETBIOSNAME="serv2"/> to <SERVER HOSTNAME="serv2"> . How do I do this using XML::Twig ? Here is a solution incorporating what I think are reasonable fixes to your question. The code below is based on the filtering example given in the documentation. #!/usr/bin/perl use strict; use warnings; use XML::Twig; my $t = XML::Twig->new( twig_roots => { SERVER => \&update }, twig_print_outside

Perl, XML::Twig, how to reading field with the same tag

冷暖自知 提交于 2019-12-05 08:11:53
I'm working on processing a XML file I receive from a partner. I do not have any influence on changing the makeup of this xml file. An extract of the XML is: <?xml version="1.0" encoding="UTF-8"?> <objects> <object> <id>VW-XJC9</id> <name>Name</name> <type>House</type> <description> <![CDATA[<p>some descrioption of the house</p>]]> </description> <localcosts> <localcost> <type>mandatory</type> <name>What kind of cost</name> <description> <![CDATA[Some text again, different than the first tag]]> </description> </localcost> </localcosts> </object> </objects> The reason I use Twig is that this

in XML:TWIG, how to stop parsing once find the interested element

╄→尐↘猪︶ㄣ 提交于 2019-12-01 19:14:24
I only want to parse an interested element of xml (e.g. see below: class element with name equals to math) and I want to stop once the first element hitting this condition is parsed. (since There is only one class whose name is math, it is unnecessary to continue once the element is already found). However, if I implement as follows, the code continues to read the whole file after it found the element i am interested (the xml file is very long so it takes long time). my question is how to stop it once the first class element with name = math is parsed? my $twig = new XML::Twig(TwigRoots => {

in XML:TWIG, how to stop parsing once find the interested element

拈花ヽ惹草 提交于 2019-12-01 17:31:24
问题 I only want to parse an interested element of xml (e.g. see below: class element with name equals to math) and I want to stop once the first element hitting this condition is parsed. (since There is only one class whose name is math, it is unnecessary to continue once the element is already found). However, if I implement as follows, the code continues to read the whole file after it found the element i am interested (the xml file is very long so it takes long time). my question is how to

how to read and change <!Doctype> tag and <?xml version=“1.0”?> in xml twig?

巧了我就是萌 提交于 2019-12-01 14:07:19
I'm new to xml twig... how to read and change <!DOCTYPE article SYSTEM "loose.dtd"> and <?xml version="1.0" encoding="UTF-8"?> . how can I modification in this tag.. because i don't know how to this read and change this tag in xml::Twig... my input: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE art SYSTEM "loose.dtd"> <art> <fr> <p>Text</p> <p>Text</p> </fr> <fr> <p>Text</p> <p>Text</p> </fr> </art> I need output as: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <DTD> <Contents type="<!DOCTYPE article SYSTEM "loose.dtd>"/> </DTD> <art> <fr> <p>Text</p> <p>Text</p> </fr> <fr> <p

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

how to get the most deeply nested element nodes using xpath? (implementation with XMLTWIG)

偶尔善良 提交于 2019-11-29 07:48:57
I need to extract (XSLT, xpath, xquery... Preferably xpath) the most deeply nested element nodes with method (DEST id="RUSSIA" method="delete"/>) and his direct ancestor (SOURCE id="AFRICA" method="modify">). I don't want to get the top nodes with methods ( main method="modify"> or main method="modify"> ). The deepest nested elements with method correspond to real actions. The top elements with method actually are dummy actions that must not be taken into account. Here is my XML sample file: <?xml version="1.0" encoding="UTF-8"?> <main method="modify"> <MACHINE method="modify"> <SOURCE id=

Updating xml attribute value based on other with Perl

强颜欢笑 提交于 2019-11-28 12:56:45
This is my sample xml file <manifest> <default> <remote>remote1</remote> <revision>rev1</revision> </default> <project> <name>common</name> <path>opensource/device</path> <revision>sa</revision> <x-ship>oss</x-ship> </project> <project> <name>external</name> <path>source/tp</path> <x-ship>none</x-ship> </project> <project> <name>ws</name> <path>opensource/ws</path> <remote>nj</remote> <revision>myno</revision> <x-ship>none</x-ship> </project> </manifest> In this I need to update the value of revision only when <path> has "opensource" string in it. I searched a lot but couldn't find anything

how to get the most deeply nested element nodes using xpath? (implementation with XMLTWIG)

邮差的信 提交于 2019-11-28 01:20:03
问题 I need to extract (XSLT, xpath, xquery... Preferably xpath) the most deeply nested element nodes with method (DEST id="RUSSIA" method="delete"/>) and his direct ancestor (SOURCE id="AFRICA" method="modify">). I don't want to get the top nodes with methods ( main method="modify"> or main method="modify"> ). The deepest nested elements with method correspond to real actions. The top elements with method actually are dummy actions that must not be taken into account. Here is my XML sample file:

Assembling XML in Perl

余生颓废 提交于 2019-11-27 09:49:57
I'm needing to make API calls to a NetApp filer. I know what raw XML I need to send: <? xml version="1.0" encoding="utf-8" ?> <!DOCTYPE netapp SYSTEM "file:/etc/netapp_filer.dtd"> <netapp version="1.7" vfiler="somevfiler" xmlns="http://www.netapp.com/filer/admin"> <nfs-exportfs-list-rules> <pathname>/vol/path/to/somewhere</pathname> </nfs-exportfs-list-rules> </netapp> Having started assembling as 'plain text', I've been trying to 'do it better' with XML::Twig . But I'm having difficulty with inserting the first two lines, as they're not 'part' of the XML tree. I've dug out XML::Twig::Elt and