user2379020
user2379020

Reputation: 322

shell command to parse xml is not functioning properly

I want to parse below xml

 <?xml version="1.0" encoding="UTF-8"?>
   <widget xmlns="http://www.w3.org/ns/widgets" xmlns:tzn="http://tzn.org/ns/widgets" id="http://yourdomain/TznTtApp" version="1.0.0" viewmodes="maximized">
   <acs orgn="*" sbdomains="true"/>
   <tzn:application id="ca9i.TznTtApp" package="ca9i" required_version="1.0"/>
   <apptype>14</apptype>
   <content src="index.html"/>
   <feature name="http://tzn.org/fate/sn.se.al"/>
   <icon src="icon.png"/>
   <name>TznTtApp</name>
 </widget>

so i am using below shell script but its not working fine. can anyone tell me the reason of this?

appType=$(echo -e 'cat //widget/apptype/text()' | xmllint --shell  /data/config.xml | grep -v "^/ >")    

when i change my xml into

<?xml version="1.0" encoding="UTF-8"?>
  <widget> 
    <apptype>14</apptype>
    <name>TznTtApp</name>
  </widget>

above command work fine so how can i parse 1st complete xml and what is the current issue in this?

Upvotes: 0

Views: 50

Answers (1)

hek2mgl
hek2mgl

Reputation: 158100

This happens because appname is inside a namespace called tzn. Either you define the namespace or you use the local-name() function:

apptype=$(xmllint --xpath '//*[local-name()="apptype"]/text()' input.xml)

Upvotes: 1

Related Questions