How to check empty string in an XML tag?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to check empty string in an XML tag?
# 1  
Old 03-07-2014
How to check empty string in an XML tag?

I have an XML tag <abc> which is empty as <abc></abc>.If the the tag is empty I want to flag the file as bad.

Please help.

Thanks
# 2  
Old 03-07-2014
Code:
awk '/<abc><\/abc>/{ print "file is bad";exit}' file.xml

# 3  
Old 03-07-2014
Untested, but should also work:
Code:
#!/bin/ksh
file=${1:-file.xml}
if grep -F '<abc></abc>' "$file"
then    printf '%s is bad.\n" "$file"
        exit 1
fi
exit 0

# 4  
Old 03-11-2014
Try something like :

Code:
$ awk -F'[<>]' '!$3 || $3!~/[[:alnum:]]/{print $0,"<-- empty"}'  <<test 
<abc></abc>
<cde>something</cde>
<def>   </def>
<fge> testeer<fge>
test

<abc></abc> <-- empty
<def>   </def> <-- empty

---------- Post updated at 08:16 PM ---------- Previous update was at 08:11 PM ----------

OR

Code:
$ awk '/<.*>([[:space:]]+|)<\/.*>/{ print $0, "<-- empty"}'  <<test 
<abc></abc>
<cde>something</cde>
<def>   </def>
<fge> testeer<fge>
test

<abc></abc> <-- empty
<def>   </def> <-- empty

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Cant check empty string

Hello So i have that script collection, in which i have a single script to create a configuration file. In there, i have multiple occourences of something like this: prj_title=$(tui-read "What is the TITLE? ($prj_name):") ] && prj_title="${prj_name/_/ }" They all work as expected, if... (5 Replies)
Discussion started by: sea
5 Replies

3. 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

4. Shell Programming and Scripting

Check if the string is empty

I am reading from a file and executing the jobs with/without parameters as the job requires. File job1 R job2 job3 Y 123 if then <job>.ksh else <job>.ksh $params fi This works fine if the line read from the file has parameters it executes like job1.ksh R But for... (2 Replies)
Discussion started by: nw2unx123
2 Replies

5. Shell Programming and Scripting

Help needed :Search and Replace a string pattern with empty in an xml file in unix

Search and Replace a string pattern with empty in an xml file in unix: My xml file would be like this : <Accounts><Name>Harish</Name><mobile>90844444444444445999 </mobile><TRIG>srcujim-1</TRIG></Accounts><Accounts><Name>Satish</Name><mobile>908999</mobile><TRIG>ettertrtt-1</TRIG></Accounts> ... (1 Reply)
Discussion started by: harish_s_ampeo
1 Replies

6. UNIX for Dummies Questions & Answers

Check to see if string var is empty

i have a veriable set var1 set var2 = abcd how can i check if var 1 is empty and if var 2 is not empty ??? (2 Replies)
Discussion started by: nirnir26
2 Replies

7. Shell Programming and Scripting

Capturing string between a xml tag

Hi All, I have an XML-: <ProcId>CES_P5010_AddVLan</ProcId> <DataVersion>yxcxycyxcycyxc</DataVersion> <JobId>OR3000055-002-1</JobId> </CesHeader> <VLanServiceList> <NopId>blu</NopId> </VLanServiceList> <StatusNPA>2</StatusNPA> ... (5 Replies)
Discussion started by: amit_iti
5 Replies

8. Shell Programming and Scripting

Check for empty string

Hello All, I have written shell script whcih at the max 3 parameters. When only one commandline argument and other two command line arguments are passed as empty string like eg : archive ' ' ' ' Then i need to check whether the commandline... (12 Replies)
Discussion started by: rahman_riyaz
12 Replies

9. Shell Programming and Scripting

How to check for null or empty string

Hi, I need to check for value not equal (<>) to 21 and not equal empty or null values. Please modify this script if then echo "$VALUE,$BSC_NAME,$BSC_ID" > $OUT_FILE/power_up.out end if TQ (5 Replies)
Discussion started by: doer
5 Replies
Login or Register to Ask a Question