0
I need to extract a few values from an XML file, and I stumbled onto XMLStarlet that seems pretty powerful. Knowing little about XML, I'm overwhelmed with the tool, and likely need only a very tiny part of it. I have a file like the following and I wanted to get, say, the following address:
<es:ipAddress>123_Westbrook</es:ipAddress>
How would I type that?
What is the significance of these extra fields like es
? I assume this brackets this particular object (the ipAddress
value, 123 Westbrook
), but what part of the path is actually given to XMLStarlet? The brackets? The parameter name? Separated by slashes?
Perhaps:
xmlstarlet sel '<bulkCmConfigDataFile xmlns:gn="JOE.xsd"> < configDat dnPrefix="Undefined"> < xn:Subnetwork id="Oz"><xn:MeContext id="BANANS"><xn:attributes><es:vsDataMeContext><es:ipAddress>
Which should point to the value 123_Westbrook
? Insert slashes? Something else?
The original file is very large, so here's the first part of the XML (many of the closing tags are missing by posting only part of it):
1 <?xml version="1.0" encoding="UTF-8"?>
2 <bulkCmConfigDataFile xmlns:un="utranNrm.xsd"
3 xmlns:es="FRED.99.88.xsd"
4 xmlns:xn="JIM.xsd" xmlns:gn="JOE.xsd" xmlns="CARL.xsd">
5 <fileHeader fileFormatVersion="THE_GOOD_OND" vendorName="Mr. Softie"/>
6 <configData dnPrefix="Undefined">
7 <xn:SubNetwork id="ROOM_4_MORE">
8 <xn:SubNetwork id="Oz">
9 <xn:attributes>
10 <xn:userDefinedNetworkType>SECRET_SERVICE</xn:userDefinedNetworkType>
11 <xn:userLabel>OZ</xn:userLabel>
12 </xn:attributes>
13 <xn:MeContext id="BANANAS">
14 <xn:VsDataContainer id="BANANAS">
15 <xn:attributes>
16 <xn:vsDataType>SECRET_SQUIRREL</xn:vsDataType>
17 <xn:vsDataFormatVersion>GOOD_HUMOR</xn:vsDataFormatVersion>
18 <es:vsDataMeContext>
19 <es:userLabel>ORANGE</es:userLabel>
20 <es:ipAddress>123_Westbrook</es:ipAddress>
21 <es:neMIMversion>S-11</es:neMIMversion>
22 <es:lostSynchronisation>SYNCHRONISED</es:lostSynchronisation>
23 <es:bcrLastChange>LAST_DATE</es:bcrLastChange>
24 <es:bctLastChange>LAST_DATE</es:bctLastChange>
25 <es:multiStandardRbs6k>uh-uh</es:multiStandardRbs6k>