XML/Input: Difference between revisions
Content added Content deleted
(→{{header|AWK}}: add solution using getXML.awk) |
(→{{header|AWK}}: add solution using xmlparser.awk) |
||
Line 110: | Line 110: | ||
{{works with|gawk}} or {{works with|nawk}} |
{{works with|gawk}} or {{works with|nawk}} |
||
<lang sh>awk -f getXML.awk sample.xml | awk ' |
<lang sh>awk -f getXML.awk sample.xml | awk ' |
||
$1 == "TAG" { |
$1 == "TAG" {tag = $2} |
||
⚫ | |||
tag = $2 |
|||
} |
|||
tag == "Student" && /Name=/ { |
|||
⚫ | |||
} |
|||
'</lang> |
'</lang> |
||
Using [http://home.vrweb.de/~juergen.kahrs/gawk/XML/xmlgawk.html#Steve-Coile_0027s-xmlparse_002eawk-script xmlparser.awk] by Steve Coile, one can do this: |
|||
producing this output |
|||
{{works with|gawk}} |
|||
<lang sh>gawk -f xmlparser.awk sample.xml | awk ' |
|||
$1 == "begin" {tag = $2} |
|||
$1 == "attrib" {attrib = $2} |
|||
$1 == "value" && tag == "STUDENT" && attrib == "name" {print $2} |
|||
'</lang> |
|||
Both of these produce this output |
|||
<pre>April |
<pre>April |
||
Bob |
Bob |