Sponsored Content
Top Forums Shell Programming and Scripting How To get the data from a tag in XML File Post 302264451 by samshaw on Thursday 4th of December 2008 03:08:49 AM
Old 12-04-2008
Re : write values of XML tags into arrays

Hello All,

Hope all is fine. I am using Bourne Shell (sh) . I have this simple XML structure ( it's very well defined and this is how this fixed structure will be). The exact sample is as follows (There will always be one value per tag):

<Users>
<Host>
<hostAddress>180.144.226.47</hostAddress>
<userName>pwdfe</userName>
<password>hjitre</password>
<instanceCount>2</instanceCount>
</Host>
<Host>
<hostAddress>180.144.226.87</hostAddress>
<userName>trrrer</userName>
<password>jhjjhhj</password>
<instanceCount>3</instanceCount>
</Host>
<Host>
<hostAddress>180.455.226.87</hostAddress>
<userName>wewqw</userName>
<password>dfsdfd</password>
<instanceCount>3</instanceCount>
</Host>
</Users>
----------------------------------------------------------------------

Now I want to create an array with only the values of the xml tags . For e.g. H_ARRAY ('180.144.226.47','180.144.226.87','180.144.226.87'). Then I will traverse throught the values of array accordingly. I am newbie to shell scripting and especially "SED" command which after repeated attempts was unable to understand. Would appreciate your help. Let me know if I missed on something,


H_ARRAY=( `echo ${hostAddress}` )
U_ARRAY=( `echo ${userName}` )
P_ARRAY=( `echo ${password}` )
I_ARRAY=( `echo ${instanceCount}` )

Thanks,
Sam
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

XML tag replacement from different XML file

We have 2 XML file 1. ORIGINAL.xml file and 2. ATTRIBUTE.xml files, In the ORIGINAL.xml we need some modification as <resourceCode>431048</resourceCode>under <item type="Manufactured"> tag - we need to grab the 431048 value from tag and pass it to database table in unix shell script to find the... (0 Replies)
Discussion started by: balrajg
0 Replies

2. Shell Programming and Scripting

Substitute partial data only within a xml tag

Hello, I have huge xml files and I need to replace only part of the data within a particular xml tag. This doesnt seem to be as simple as it sounds. I have searched everywhere and couldnt find any solution. Ex: In the below case I would like "def" to be replaced by "xyz" only when found in... (8 Replies)
Discussion started by: roshanjain2
8 Replies

3. Shell Programming and Scripting

How to retrieve the value from XML tag whose end tag is in next line

Hi All, Find the following code: <Universal>D38x82j1JJ </Universal> I want to retrieve the value of <Universal> tag as below: Please help me. (3 Replies)
Discussion started by: mjavalkar
3 Replies

4. Shell Programming and Scripting

How to add the multiple lines of xml tags before a particular xml tag in a file

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)
Discussion started by: mjavalkar
0 Replies

5. UNIX for Advanced & Expert Users

Shell Script to read XML tags and the data within that tag

Hi unix Gurus, I am really new to Unix Scripting. Please help me to create a shell script which reads the xml file and from that i need to fetch a particular information. For example <SOURCE BUSINESSNAME ="" DATABASETYPE ="Teradata" DBDNAME ="DWPROD3" DESCRIPTION ="" NAME... (2 Replies)
Discussion started by: SmilePlease
2 Replies

6. Shell Programming and Scripting

To search for a particular tag in xml and collate all similar tag values and display them count

I want to basically do the below thing. Suppose there is a tag called object1. I want to display an output for all similar tag values under heading of Object 1 and the count of the xmls. Please help File: <xml><object1>house</object1><object2>child</object2>... (9 Replies)
Discussion started by: srkmish
9 Replies

7. Shell Programming and Scripting

Update particular tag in a XML file

Below is the content in my XML file <name>XXX</name> <eventType>Uptime</eventType> <eventType>Delay</eventType> <eventType>Delay</eventType> <name>YYY</name> <eventType>Uptime</eventType> <eventType>Delay</eventType> ... (12 Replies)
Discussion started by: Viswanatheee55
12 Replies

8. Shell Programming and Scripting

Moving XML tag/contents after specific XML tag within same file

Hi Forum. I have an XML file with the following requirement to move the <AdditionalAccountHolders> tag and its content right after the <accountHolderName> tag within the same file but I'm not sure how to accomplish this through a Unix script. Any feedback will be greatly appreciated. ... (19 Replies)
Discussion started by: pchang
19 Replies

9. UNIX for Beginners Questions & Answers

Grepping multiple XML tag results from XML file.

I want to write a one line script that outputs the result of multiple xml tags from a XML file. For example I have a XML file which has below XML tags in the file: <EMAIL>***</EMAIL> <CUSTOMER_ID>****</CUSTOMER_ID> <BRANDID>***</BRANDID> Now I want to grep the values of all these specified... (1 Reply)
Discussion started by: shubh752
1 Replies
__SINPI(3)						   BSD Library Functions Manual 						__SINPI(3)

NAME
__sinpi -- sine-pi function SYNOPSIS
#include <math.h> float __sinpif(float x); double __sinpi(double x); DESCRIPTION
The __sinpi() function returns the sine of pi times x (measured in radians). This can be computed more accurately than sin(M_PI * x), because it can implicitly use as many bits of pi as are necessary to deliver a well-rounded result, instead of the 53-bits to which M_PI is limited. For large x it may also be more efficient, as the argument reduction involved is significantly simpler. This function may be especially useful for working with degrees; whereas sin(M_PI * x / 180.0) cannot produce exact results for angles that naively "should" be exact, like 180 degrees, __sinpi(x / 180.0) can be computed exactly. SPECIAL VALUES
__sinpi(-x) is the same as - __sinpi(x) for any finite x. __sinpi(+-0) returns +-0. __sinpi(n) returns +0 for any positive integer n. __sinpi(n + 0.5) returns +1 for any even integer n. __sinpi(n + 0.5) returns -1 for any odd integer n. __sinpi(+-infinity) raises the invalid floating-point exception and returns NaN. VECTOR OPERATIONS
If you need to apply the __sinpi() function to SIMD vectors or arrays, using the following functions provided by the Accelerate.framework may be useful: #include <Accelerate/Accelerate.h> vFloat vsinpif(vFloat x); void vvsinpif(float *y, float *x, const int n); void vvsinpi(double *y, double *x, const int n); SEE ALSO
__cospi(3), __tanpi(3), __sincospi(3), math(3) BSD
December 15, 2012 BSD
All times are GMT -4. The time now is 01:55 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy