0

I want to use bash scripts to get certain value in xml file, for example:

<?xml version="1.0" encoding="UTF-8"?>

-<Entities schemaVersion="1010" revision="2" modelPersistenceProviderPackage="PostgresPersistenceProviderPackage" minorVersion="1" majorVersion="8" build="b51">


-<ThingTemplates>

-<ThingShape>


-<PropertyDefinitions>

<PropertyDefinition name="version" description="" ordinal="45" baseType="STRING" aspect.defaultValue="1.0.0" isLocalOnly="false" category="" aspect.isReadOnly="false" aspect.isPersistent="false" aspect.isLogged="false" aspect.dataChangeType="VALUE" aspect.cacheTime="0.0"/>

</PropertyDefinitions>


</ThingTemplate>

</ThingTemplates>

</Entities>

How can I get the version value (1.0.0) from the xml file ?

Eva Cheung
  • 119
  • 1
  • 4
  • 14
  • 1
    The general recommendation for extracting data from an XML file is to use an XML parser, because an XML definition can be written to span many lines, might contain data which also look like XML tags, and so on. In your case it means that you shouldn't use POSIX shell, but some other language - ideally one which already comes with XML parsers included (for instance, Ruby or Perl). Even if the XML file is machine-generated and known to always have a fixed structure, I wouldn't use Posix shell but, for instance, `awk`. – user1934428 Mar 23 '18 at 07:24
  • Possible duplicate of [How to parse XML in Bash?](https://stackoverflow.com/questions/893585/how-to-parse-xml-in-bash) – ariefbayu Mar 26 '18 at 02:03

0 Answers0