Sponsored Content
Top Forums Shell Programming and Scripting Trying to pull a variable out of an xml file... Post 302583549 by Renfield on Tuesday 20th of December 2011 05:27:34 PM
Old 12-20-2011
Trying to pull a variable out of an xml file...

Hello. I'm new to *ix and am trying to pull a variable or two from an xml document. The document is in the format:

Code:
<name>7_3(A).mov</name>
      <description>Some description from a file</description>
      <updatename>7_3_A.mov</updatename>
      <updatepath>Dailies Released</updatepath>
      <playlist>Selects Day 5,Dailies Day 5</playlist>

What I need to do is take the value or values from inside the <playlist> tags and assign them to variables. So, for this example, I'd like to be able to set $playlist1 to "Selects Day 5" and $playlist2 to "Dailies Day 5." The values in that xml tag will always be comma separated and there can be any number of them. I used grep to find the playlist lines, but don't know what to do next.

There are many more lines for each item described in the xml and there will be other instances of the <playlist> tag. I'll need to ignore instances of any value already set so, for example, once I've got the values "Selects Day 5" and "Dailies Day 5" from the above example I will need to ignore any further instances of those values until the script is executed again.

Any help would really be appreciated.

Thanks!

Dan
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

pull xml's from logs

Hi Frnds I Want to pull xml's from logs based on the below condition.In each log having so many xml's it's taking so much of time to search all logs manually...can u please provide solution USER:ECMINT CONV:GETARPLNICHUBTST <CardNbr>376703134104004</CardNbr> </Envelope> Response XML:... (3 Replies)
Discussion started by: pb18798
3 Replies

2. Programming

Accessing environmet variable in xml file

Hi I have certain environmenet variables defined in .profile: export DBNAME="mydb" export DBHOST="devbox.us.abc.com" export DBPORT="1111" export PASSWORD="mypwd" export MMUSER="myid" I also have an xml file defined like: <CONFIG> <DEFAULTS operator="oraread"> <PROPERTY... (2 Replies)
Discussion started by: neeto
2 Replies

3. Shell Programming and Scripting

How do I pull a substring out of a file?

I'm new to shell scripting and am trying to write a small script that pulls a substring out of a file that has a few lines of text in it. The file will eventually have a lot of text, I just put a few lines in it for testing purposes. Anyway, this is what I have so far... #!/bin/ksh ... (4 Replies)
Discussion started by: enator45
4 Replies

4. Shell Programming and Scripting

How pull the Data from the file and should be mailed

Hi All, I need to pull the data from a file from 2 set of directories & should be mailed. I have a code , it is failing for some reason. Do somebody correct me where my script is going wrong. Directories: 1st Set of Directory /176_PS/Transactions/**/syslog.log ** : prd1 prd2... (2 Replies)
Discussion started by: raghunsi
2 Replies

5. Shell Programming and Scripting

parsing data from xml file is failing can't open variable

Created a korn shell script, everything is is working except this section, the variable $SYSINFO is being set, but the NASIP & NASDEV are failing, it appears to be treating the config.xml file config directory and xml as the file. Need a second set of eyes to tell me where I am messing up. #... (3 Replies)
Discussion started by: juanb25
3 Replies

6. Shell Programming and Scripting

wish to use shell variable in xml file, is it possible?

greetings, i have an executable that reads its config from an xml file. this executable needs to be started as the current user. there is a line in the xml file that contains the following: <option name="USER_ID" value="myuserid"/>the current value is an actual user id (mine) as it was... (3 Replies)
Discussion started by: crimso
3 Replies

7. Shell Programming and Scripting

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: NEARLY_FILE='<?xml version="1.0" encoding="iso-8859-1"?><html><set label="09/07/29"... (0 Replies)
Discussion started by: OleM2k
0 Replies

8. Shell Programming and Scripting

Help required in Splitting a xml file into multiple and appending it in another .xml file

HI All, I have to split a xml file into multiple xml files and append it in another .xml file. for example below is a sample xml and using shell script i have to split it into three xml files and append all the three xmls in a .xml file. Can some one help plz. eg: <?xml version="1.0"?>... (4 Replies)
Discussion started by: ganesan kulasek
4 Replies

9. Shell Programming and Scripting

Insert value of env variable in xml file

Hello, I have the following variables set in my env echo $MY_XSD_FILE /home/jak/sample.xsd echo $MY_INTERVAL_VALUE 4 I want to insert them between the xml tags in my xml file cat sample.xml ::::::::::::::: ::::::::::::::: <property name="FILE"></property> :::::::::::::::::::::::... (2 Replies)
Discussion started by: jakSun8
2 Replies

10. UNIX for Beginners Questions & Answers

How to pull multiple XML tags from the same XML file in Shell.?

I'm searching for the names of a TV show in the XML file I've attached at the end of this post. What I'm trying to do now is pull out/list the data from each of the <SeriesName> tags throughout the document. Currently, I'm only able to get data the first instance of that XML field using the... (9 Replies)
Discussion started by: hungryd
9 Replies
SIMPLEXML_LOAD_FILE(3)							 1						    SIMPLEXML_LOAD_FILE(3)

simplexml_load_file - Interprets an XML file into an object

SYNOPSIS
SimpleXMLElement simplexml_load_file (string $filename, [string $class_name = "SimpleXMLElement"], [int $options], [string $ns = ""], [bool $is_prefix = false]) DESCRIPTION
Convert the well-formed XML document in the given file to an object. PARAMETERS
o $filename - Path to the XML file Note Libxml 2 unescapes the URI, so if you want to pass e.g. b&c as the URI parameter a, you have to call sim- plexml_load_file(rawurlencode('http://example.com/?a=' . urlencode('b&c'))). Since PHP 5.1.0 you don't need to do this because PHP will do it for you. o $class_name - You may use this optional parameter so that simplexml_load_file(3) will return an object of the specified class. That class should extend the SimpleXMLElement class. o $options - Since PHP 5.1.0 and Libxml 2.6.0, you may also use the $options parameter to specify additional Libxml parameters. o $ns - Namespace prefix or URI. o $is_prefix - TRUE if $ns is a prefix, FALSE if it's a URI; defaults to FALSE. RETURN VALUES
Returns an object of class SimpleXMLElement with properties containing the data held within the XML document, or FALSE on failure. ERRORS
/EXCEPTIONS Produces an E_WARNING error message for each error found in the XML data. Tip Use libxml_use_internal_errors(3) to suppress all XML errors, and libxml_get_errors(3) to iterate over them afterwards. EXAMPLES
Example #1 Interpret an XML document <?php // The file test.xml contains an XML document with a root element // and at least an element /[root]/title. if (file_exists('test.xml')) { $xml = simplexml_load_file('test.xml'); print_r($xml); } else { exit('Failed to open test.xml.'); } ?> This script will display, on success: SimpleXMLElement Object ( [title] => Example Title ... ) At this point, you can go about using $xml->title and any other elements. SEE ALSO
simplexml_load_string(3), SimpleXMLElement::__construct, "Dealing with XML errors", libxml_use_internal_errors(3), "Basic SimpleXML usage". PHP Documentation Group SIMPLEXML_LOAD_FILE(3)
All times are GMT -4. The time now is 10:40 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy