Hello, I need a script to edit a custom XML, although I know it should be fairly easy to create such a script, I'm failing miserably.
The script should be able to read from a file containing the ids of one tag of the xml (<content contentid="XXX".... for example) and then remove this content.
For instance, for the simple XML file like this:
If one has the codes 0001, 0012 and 0013 on the file, it should become this xml file:
Now, I'm pretty sure this should be easy, but I'm having a VERY big amount of trouble by doing this (I've tried PERL, Ruby, PHP and even sed with grep) can anyone help me?
The ^ and $ decorations are probably unnecessary, if the result is mainly intended to be machine-readable. The real beef is the -0777 option and the .*? regex coupled with the /s modifier. See the Perl FAQ for more on these.
Hum...that seems good, but where do I put the input code to remove from the XML? (I'm really no expert at regular expressions...yet)
Also, please remember that this codes are fed up by a file, and honestly, I know absolutely nothing about PERL...or at least not enough to read a file and feed every line (removing the \n) to a specific regexp.
That's the entire program. Replace file.xml with the name of the input file. Redirect to a temporary file, or use perl -i to change the original file "in place".
This I understood, the file.xml is the xml file to remove the content from, but how do I feed the perl program with the codes to remove? I tried creating a big file with all the codes piped (e.g.: 0001|0002|3142|5342|7890....) and then cat it with the perl program you passed:
But it didn't worked. Am I missing something here?
It's looking for literally the contents of the file, you need to process it to make a decent regular expression out of it.
Better do that in Perl directly, too.
This isn't particularly elegant; there is some pressure to put this into a file rather than try to pretend it's still a one-liner. You should probably refactor it a bit then.
Last edited by era; 06-05-2008 at 09:36 AM..
Reason: Oops, <C> is influenced by -0777 too
I've got two different files and want to compare them.
File 1 :
HTML Code:
<response ticketId="944" type="getQueryResults"><status>COMPLETE</status><description>Query results fetched successfully</description><recordSet totalCount="1" type="sms_records"><record... (1 Reply)
Hi All,
I'm stuck with adding multiple lines(irrespective of line number) to a file before a particular xml tag. Please help me.
<A>testing_Location</A>
<value>LA</value>
<zone>US</zone>
<B>Region</B>
<value>Russia</value>
<zone>Washington</zone>
<C>Country</C>... (0 Replies)
Hi everyone, I am trying to access an online XML file, for example: <a href="http://www.rgraph.net/sample.xml" target="_blank">http://www.rgraph.net/sample.xml using HTML.
<html>
<body>
<script type="text/javascript">
if (window.XMLHttpRequest)
{// code for IE7+, Firefox,... (1 Reply)
I have looked at other responses and never was able to modify to work.
data is:
<?xml version="1.0"?>
<note version="0.3" xmlns:link="http://beatniksoftware.com/tomboy/link" xmlns:size="http://beatniksoftware.com/tomboy/size" xmlns="http://beatniksoftware.com/tomboy"><title>recoll</title><text... (12 Replies)
Hi,
I have got a zip (binary) file transferred from MacOS (thus it has additional __MACOSX directory packed inside). On extracting this zip, there are few *.xml files available. When I opened this *.xml file in vim editor using Cygwin (on windows) the editor displayed in the bottom. I tried... (4 Replies)
HI,
I have XML file which is having values as Spanish character (UTF-8 encoding). I am using XML::parser module but my code is not able to read those characters. I did goggling but not able to find suitable solution. Anybody please help me out.
XML file having characters like: ñ
I am... (1 Reply)
Hi All,
I am trying to run the following program
#!/usr/bin/perl
# use module
use XML::Simple;
use Data::Dumper;
# create object
$xml = new XML::Simple;
# read XML file
$data = $xml->XMLin("dump.xml");
# print output
print Dumper($dump);
At first i had the error mesage saying... (5 Replies)
I probably could have done this at one time, but, the years and no need has left my scripting skills lacking and I'm unable to work this problem out. https://www.unix.com/images/smilies/frown.gif
:(
Using Linux, have a great many xml files in which there may be multiple occurrence of a line of... (13 Replies)
Hi,
I have a config.xml which cointains the tags like
<CONFIG>
<PROPERTY name="port" value="1111"/>
<PROPERTY name="dbname" value="ABCDE"/>
<PROPERTY name="connectstring" value="xyz/pwd"/>
</CONFIG>
This file is in some directory at UNix box.
I need to write a... (4 Replies)
I'm an absolute newbie for unix...
For my work, I have to import a xml file in our system (jsp+sql) via putty telnet.
Once i have copied the file in the right directory, I launch this command:
./thisImport -i input/thisImport/newimport.20071130.xml -l 10 -t
this is a test (as you can see),... (1 Reply)