LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-06-2016, 04:23 AM   #1
addy54
LQ Newbie
 
Registered: Mar 2016
Posts: 13

Rep: Reputation: Disabled
Need to find all contents of XML tag if certain parameter value match


Hello All,

I've below test XML and I am trying to get whole tag parameters in which CONFIRM="1"

Quote:
<APPLICATION=""

APR="1"

AUG="1"

CHANGE_DATE="20160410"

CHANGE_TIME="045325"

CHANGE_USERID="system"

CONFIRM="0"

CREATION_DATE="20100520"

CREATION_TIME="210945"

CRITICAL="0"

CYCLIC="0"

DAYSCAL="CTMCAL5N"

DAYS_AND_OR="OR"

DEC="1"

FEB="1"

HOSTNAME="abc.xyz.com"

SHIFTNUM="+00"

SYSDB="0">

<SHOUT TIME="0800"/>

<\APPLICATION>

<APPLICATION=""

APR="1"

AUG="1"

CHANGE_DATE="20160410"

CHANGE_TIME="045331"

CHANGE_USERID="system"

CONFIRM="1"

CREATION_DATE="20100520"

CREATION_TIME="210945"

CRITICAL="0"

CYCLIC="0"

DAYSCAL="CTMCAL5N"

DAYS_AND_OR="OR"

DEC="1"

FEB="1"

HOSTNAME="abc.pqr.com"

SHIFTNUM="+00"

SYSDB="0">

<SHOUT TIME="0800"/>

<\APPLICATION>
So in above example I should get all values of tag <Application ... >

I am trying below command but it is not working

cat test.xml | sed -n '/CONFIRM="1"/ s/<APPLICATION .*>\(.*\)<\APPLICATION>/&/p'


Can somebodey help me here?
 
Old 05-06-2016, 06:04 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,128

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
Parsing xml using shell tools is a mugs game. Can be done, but you have to be very particular in what you ask for. Most of the time you get what you asked for. Which is nothing like what you thought you asked for.

Use a xml aware tool - there are innumerable threads about this - try some searches. xmllint might be a start, or cpan for perl.
 
Old 05-06-2016, 06:41 AM   #3
addy54
LQ Newbie
 
Registered: Mar 2016
Posts: 13

Original Poster
Rep: Reputation: Disabled
Thanks a lot

I've used xmllint and it worked.

echo 'cat //APPLICATION[@CONFIRM="1"]' | xmllint --shell test.xml
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Extract values between xml tag boby.kumar Linux - Newbie 2 11-02-2015 10:31 AM
[SOLVED] Trying to parse a value from XML tag for a variable n3wtux Linux - Newbie 1 07-26-2013 04:51 PM
how to add xml-stylesheet tag in a XML File using libxml2 ? peacemission Programming 6 05-26-2012 02:20 AM
how to find the end tag in xml file. mariakumar Linux - General 1 12-21-2010 10:12 AM
How to find the tag value in xml file through unix shell script hussain.s Linux - General 2 11-03-2010 07:52 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration