How to parse xml file in variable-string?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to parse xml file in variable-string?
# 1  
Old 06-19-2012
How to parse xml file in variable-string?

In the wake of the post: how-parse-following-xml-file
Thank you for the very useful chakrapani response 302355585-post4 !

A close question.
How to pass a file to xmllint in variable?
For example, let it be:
Code:
NEARLY_FILE='<?xml version="1.0" encoding="iso-8859-1"?><html><set label="09/07/29" value="1241.90"/></html>'

Then I want to do something like this:
Code:
echo 'cat /html' | xmllint --shell $NEARLY_FILE

and get:
Code:
<html><set label="09/07/29" value="1241.90"/></html>

Thanks in advance!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parse XML File.

HI Guys I have Below XML File : <xn:SubNetwork id="XYZ"> <xn:SubNetwork id="C01"> <xn:MeContext id="CO1"> <xn:ManagedElement id="1"> <un:RncFunction id="1"> <un:UtranCell id="NY431"> ... (2 Replies)
Discussion started by: pareshkp
2 Replies

2. UNIX for Dummies Questions & Answers

Parse xml file

HI Guys, Input .XML <xn:MeContext id="L0307"> <xn:ManagedElement id="1"> <xn:VsDataContainer id="1"> <xn:attributes> <xn:vsDataType>vsDataENodeBFunction</xn:vsDataType> ... (3 Replies)
Discussion started by: pareshkp
3 Replies

3. Shell Programming and Scripting

parse xml file

Hello all, Given the following extract from a xml file with multiple <JOB> .... </JOB> entries <JOB APPLICATION="APP" APR="0" AUG="0" AUTHOR="AUT" AUTOARCH="0" CMDLINE="/tmp/test1 %%var" CONFIRM="1" CREATION_DATE="20100430" CREATION_TIME="130739" ... (2 Replies)
Discussion started by: cabrao
2 Replies

4. Shell Programming and Scripting

How can I parse xml file?

How can I parse file containing xml ? I am sure that its best to use perl - but my perl is not very good - can someone help? Example below contents of file containing the xml - I basically want to parse the file and have each field contained in a variable.. ie. I want to store the account... (14 Replies)
Discussion started by: frustrated1
14 Replies

5. Shell Programming and Scripting

Parse String from a Variable

Hello, Is there a quick way to parse the values from a variable? The variable has the following sample input: TA= The values of the TA variable is not fixed/hardcoded Basically I need to get the IV_Test and PF_SAPP_FWK values. I created a script that first use sed to remove ,... (3 Replies)
Discussion started by: racbern
3 Replies

6. Shell Programming and Scripting

Parse a string in XML file using shell script

Hi! I'm just new here and don't know much about shell scripting. I just want to ask for help in creating a shell script that will parse a string or value of the status in the xml file. Please sample xml file below. Can you please help me create a simple script to get the value of status? Also it... (46 Replies)
Discussion started by: ayhanne
46 Replies

7. Shell Programming and Scripting

Parse String in XML file

Hello All, I am new to this and I need to parse an XML file. Here's the XML Input File: <Report version="1.2"> <summary fatals="0" testcases="1" expected_fails="0" unexpected_passes="0" warnings="9" tests="21" errors="0" fails="1" passes="20" /> <testresult... (4 Replies)
Discussion started by: racbern
4 Replies

8. Shell Programming and Scripting

Parse XML file

Hi, I need to parse the following XML data enclosed in <a> </a> XML tag using shell script. <X> ..... </X> <a> <b> <c>data1</c> <c>data2</c> </b> <d> <c>data3</c> </d> </a> <XX> ... </XX> (5 Replies)
Discussion started by: viki
5 Replies

9. Shell Programming and Scripting

parse a string variable

Hello all, need a little help. I have an input variable such as ARGV which equals something like /use/home/name/script/test.dat I need to be able to get just the "test.dat" (i.e. the file name) at the end of the directory and the directory can be anything and any length. To put it another... (3 Replies)
Discussion started by: methos
3 Replies

10. Shell Programming and Scripting

How to parse a XML file using PERL and XML::DOm

I need to know the way. I have got parsing down some nodes. But I was unable to get the child node perfectly. If you have code please send it. It will be very useful for me. (0 Replies)
Discussion started by: girigopal
0 Replies
Login or Register to Ask a Question
XML::SAX::Pipeline(3pm) 				User Contributed Perl Documentation				   XML::SAX::Pipeline(3pm)

NAME
XML::SAX::Pipeline - Manage a linear pipeline of SAX processors SYNOPSIS
use XML::SAX::Machines qw( Pipeline ); ## Most common way use XML::Fitler::Foo; my $m = Pipeline( XML::Filter::Foo->new, ## Create it manually "XML::Filter::Bar", ## Or let Pipeline load & create it "XML::Filter::Baz", { ## Normal options Handler => $h, } ); ## To choose the default parser automatically if XML::Filter::Foo ## does not implement a parse_file method, just pretend the Pipeline ## is a parser: $m->parse_file( "blah" ); ## To feed the pipeline from an upstream processor, treat it like ## any other SAX filter: my $p = Some::SAX::Generator->new( Handler => $m ); ## To read a file or the output from a subprocess: my $m = Pipeline( "<infile.txt" ); my $m = Pipeline( "spew_xml |" ); ## To send output to a file handle, file, or process: my $m = Pipeline( ..., *STDOUT ); my $m = Pipeline( ..., ">outfile.txt" ); my $m = Pipeline( ..., "| xmllint --format -" ); DESCRIPTION
An XML::SAX::Pipeline is a linear sequence SAX processors. Events passed to the pipeline are received by the "Intake" end of the pipeline and the last filter to process events in the pipeline passes the events out the "Exhaust" to the filter set as the pipeline's handler: +-----------------------------------------------------------+ | An XML:SAX::Pipeline | | Intake | | +---------+ +---------+ +---------+ Exhaust | --+-->| Stage_0 |--->| Stage_1 |-->...-->| Stage_N |----------+-----> | +---------+ +---------+ +---------+ | +-----------------------------------------------------------+ As with all SAX machines, a pipeline can also create an ad hoc parser (using XML::SAX::ParserFactory) if you ask it to parse something and the first SAX processer in the pipeline can't handle a parse request: +-------------------------------------------------------+ | An XML:SAX::Pipeline | | Intake | | +--------+ +---------+ +---------+ Exhaust | | | Parser |-->| Stage_0 |-->...-->| Stage_N |----------+-----> | +--------+ +---------+ +---------+ | +-------------------------------------------------------+ or if you specify an input file like so: my $m = Pipeline(qw( <input_file.xml XML::Filter::Bar XML::Filter::Baz )); Pipelines (and machines) can also create ad hoc XML::SAX::Writer instances when you specify an output file handle (as shown in the SYNOPSIS) or an output file: my $m = Pipeline(qw( XML::Filter::Bar XML::Filter::Baz >output_file.xml )); And, thanks to Perl's magic open (see perlopentut), you can read and write from processes: my $m = Pipeline( "gen_xml.pl |", "XML::Filter::Bar", "XML::Filter::Baz", "| consume_xml.pl", ); This can be used with an XML::SAX::Tap to place a handy debugging tap in a pipeline (or other machine): my $m = Pipeline( "<input_file.xml" "XML::Filter::Bar", Tap( "| xmllint --format -" ), "XML::Filter::Baz", ">output_file.xml", ); METHODS
See XML::SAX::Machine for most of the methods. new my $pipeline = XML::SAX::Pipeline->new( @processors, \%options ); Creates a pipeline and links all of the given processors together. Longhand for Pipeline(). AUTHOR
Barrie Slaymaker <barries@slaysys.com> COPYRIGHT
Copyright 2002, Barrie Slaymaker, All Rights Reserved. You may use this module under the terms of the Artistic, GNU Public, or BSD licenses, your choice. perl v5.10.0 2009-06-11 XML::SAX::Pipeline(3pm)