Visit Our UNIX and Linux User Community


Extracting data from an xml file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Extracting data from an xml file
# 1  
Old 07-16-2010
Extracting data from an xml file

Hello,

Please can someone assist.

I have the following xml file:
Code:
<?xml version="1.0" encoding="utf-8" ?> 
- <PUTTRIGGER xmlns:xsd="http://www.test.org/2001/XMLSchema" xmlns:xsi="http://www.test.org/2001/XMLSchema-instance" APPLICATIONNUMBER="0501160" ACCOUNTNAME="Mrs S Test" PUTFILENAME="91C8A853FD6E4D5BAC92085165111111.afp.zip" PUTFILEZIPPED="Y" PUTFILENAMEINZIP="91C8A853FD6E4D5BAC92085165111111.afp" ENVIRONMENT="PRODLB" PACKCONTROLNUMBER="101" PACKCONTROLNAME="RU_Offer_pack_app_eng_wales" xmlns="http://Omiga.test.test/test">
- <DOCUMENTLIST>
  <DOCUMENT DOCUMENTGUID="2764E71073424046BCF6A65573111111" EVENTGUID="1664FF8926154B49A94AD879D11111" FILEGUID="8728DF2445B24D129F00B6ACEA111111" FILECONTENTSGUID="8728DF2445B24D129F00B6ACEA63869F" MOBIUSLOCATION="0501111|TEST1_RTF|20010621171505|0501129-71111|1" FILEVERSION="V1" DOCUMENTCATEGORY="Pre-completion" HOSTTEMPLATENAME="Offer - Copy To Broker" FILESIZE="0" DATECREATED="2001-06-22 16:20:23.570" CREATEDBY="TestR" METADATA="" /> 
  <DOCUMENT DOCUMENTGUID="BF7B31EBD1BD4F2A91DBC090B9111111" EVENTGUID="27E2424AEC20431EAA6CAE1D4111111" FILEGUID="F897BF52CEFA4EC1BDA4F041D6111111" FILECONTENTSGUID="F897BF52CEFA4EC1BDA4F041D6111111" MOBIUSLOCATION="0501111|EPSOM_RTF|20070622111111|0501129-101111|1" FILEVERSION="V1" DOCUMENTCATEGORY="Pre-completion" HOSTTEMPLATENAME="Offer Document" FILESIZE="0" DATECREATED="2001-06-22 16:20:32.223" CREATEDBY="TestJ" METADATA="" /> 
  </DOCUMENTLIST>
  </PUTTRIGGER>

I need to extract the data into a file that is in quotes after APPLICATIONNUMBER and DOCUMENTCATEGORY.

Last edited by radoulov; 07-16-2010 at 09:59 AM.. Reason: Please use code tags!
# 2  
Old 07-16-2010
If those entries don't span multiple lines:

Code:
sed -n '
  s/.*APPLICATIONNUMBER="\([^"]*\).*/\1/p
  s/.*DOCUMENTCATEGORY="\([^"]*\).*/\1/p
  ' infile

With some sed implementations you can use even:

Code:
sed -n '
  s/.*\(APPLICATIONNUMBER\|DOCUMENTCATEGORY\)="\([^"]*\).*/\2/p
  ' infile

# 3  
Old 07-19-2010
Extracting data from xml

Radoulov

I am still having trouble with extracting the information.
I tried to simplify it using:
Code:
sed -n 's/.*APPLICATIONNUMBER="\([^"]*\).*/\1/p' infile.xml > dolph

Comes up with the following:
Code:
sed: Function s/.*APPLICATIONNUMBER="\([^"]*\).*/\1/p s/.*DOCUMENTCATEGORY="\([^"]*\).*/\1/p  cannot be parsed.

Any ideas.

Thanks
# 4  
Old 07-19-2010
Don't try to simplify, just run the command I gave you.
# 5  
Old 07-19-2010
I tried this but got no output:
Code:
sed -n '
> s/.*APPLICATIONNUMBER="\([^"]*\).*/\1/p
> s/.*DOCUMENTCATEGORY="\([^"]*\).*/\1/p
> ' tescobank.xml
sed: Function s/.*APPLICATIONNUMBER="\([^"]*\).*/\1/p  cannot be parsed.


Last edited by radoulov; 07-19-2010 at 06:09 AM.. Reason: Added code tags!
# 6  
Old 07-19-2010
Hm, could you put the commands inside a file and then run it like this:

s.sed

Code:
s/.*APPLICATIONNUMBER="\([^"]*\).*/\1/p
s/.*DOCUMENTCATEGORY="\([^"]*\).*/\1/p

Code:
sed -nf s.sed  tescobank.xml

# 7  
Old 07-19-2010
tried this, there is no output or errors?
 

Previous Thread | Next Thread
Test Your Knowledge in Computers #906
Difficulty: Easy
A Unix shell repeatedly prints a prompt, waits for a command line on stdin, and then carries out some action, as directed by the contents of the command line.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Extracting data between continuous non empty xml tags

Hi, I need help in extracting only the phone numbers between the continuous non empty xml tags in unix. I searched through a lot of forum but i did not get exact result for my query. Please help Given below is the sample pipe delimited file. I have a lot of tags before and after... (6 Replies)
Discussion started by: zen01234
6 Replies

2. Shell Programming and Scripting

Need Help in extracting data from XML File

Hi All My input file is an XML and it has some tags and data rows at end. Starting of data rows is <rs:data> and ending of data rows is </rs:data>. Within sample data rows (2 rows) shown below, I want to extract data value after equal to sign (until space or "/" sign). So if XML data... (7 Replies)
Discussion started by: vx04
7 Replies

3. Shell Programming and Scripting

Extracting the tag name from an xml file

Hi, My requirement is something like this, I have a xml file that contains some tags and nested tags, <n:tag_name1> <n:sub_tag1>val1</n:sub_tag1> <n:sub_tag2>val2</n:sub_tag2> </n:tag_name1> <n:tag_name2> <n:sub_tag1>value</n:sub_tag1> ... (6 Replies)
Discussion started by: Little
6 Replies

4. Shell Programming and Scripting

Reading XML file and extracting value

Dear All, I am reading one XML file to extract value from the particular tag:- Sample xml is below:- <KeyValuePairs> <Key>TestString</Key> <Value>Test12_Pollings</Value> </KeyValuePairs> I want to read the value for the KEY tag and there will be multiple key tags :- awk... (4 Replies)
Discussion started by: sharsour
4 Replies

5. Shell Programming and Scripting

Extracting content from xml file

Hello All, Hope you are doing well!!!!! I have a small code in the below format in xml file: <UML:ModelElement.taggedValue> <UML:TaggedValue tag="documentation" value="This sequence&#xA;&#xA;HLD_EA_0001X&#xA;HLD_DOORS_002X"/> <UML:TaggedValue tag="documentation" value="This... (11 Replies)
Discussion started by: suvendu4urs
11 Replies

6. Shell Programming and Scripting

Need help in extracting data from xml file

Hello, This is my first post in here, so excuse me if I sound too noob here! I need to extract the path "/apps/mp/installedApps/V61/HRO/hrms_01698_A_qa.ear" from the below xml extract. The path will always appear with the key "binariesURL" <deployedObject... (6 Replies)
Discussion started by: abhishek2386
6 Replies

7. UNIX for Dummies Questions & Answers

Extracting values from an XML file

Hello People, I have an xml file from which I need to extract the values of the parameters using UNIX shell commands. Ex : Input is like : <Name>Roger</Name> or <Address>MI</Address> I need the output as just : Roger or MI with the tags removed. Please help. (1 Reply)
Discussion started by: sushant172
1 Replies

8. Shell Programming and Scripting

Extracting a part of XML File

Hi Guys, I have a very large XML feed (2.7 MB) which crashes the server at the time of parsing. Now to reduce the load on the server I have a cron job running every 5 min.'s. This job will get the file from the feed host and keep it in the local machine. This does not solve the problem as... (9 Replies)
Discussion started by: shridhard
9 Replies

9. Shell Programming and Scripting

Extracting Data from xml file

Hi ppl out there... Can anyone help me with the shell script to extract data from an xml file. My xml file looks like : - <servlet> <servlet-name>FrontServlet</servlet-name> <display-name>FrontServlet</display-name> ... (3 Replies)
Discussion started by: nishana
3 Replies

10. Shell Programming and Scripting

extracting XML file using sed

Hello folks I want to extract data between certain tag in XML file using 'sed' <xml> ......... .......... <one>XXXXXXXXXXXXXXXXXXXX</one> ...... Anyone ?Thank you (7 Replies)
Discussion started by: pujansrt
7 Replies

Featured Tech Videos