An XML Document as a Text File
An XML file can be viewed as a text file, in which you find a mixture of the real data and markup language. You can find a lot of free tools on the market that excel in text manipulation using regular expressions: awk, grep, perl, and python.
If you want to know how many musicians you have in your musicians.xml file, you can use the following grep command:
grep -c "<musician>" musicians.xml
Here's a breakdown of this command:
- • -c is the option to print only the number of lines matched.
- • Within quotes, the text (or pattern) to be matched, in this case the start tag of element musician.
- • The file to be searched, for example, musicians.xml.
This example will return 4.