XML/XPath: Difference between revisions

Content added Content deleted
(→‎{{header|REXX}}: added a second version (generic parsing).)
m (→‎generic parsing: adjusted indentations, add whitespace to argument list.)
Line 1,831: Line 1,831:
end /*j*/
end /*j*/


call parser 'item',0 /*go and parse the all ITEMs. */
call parser 'item', 0 /*go and parse the all ITEMs. */
say center('first item:',@L.1,'─') /*show a nicely formatted header.*/
say center('first item:',@L.1,'─') /*show a nicely formatted header.*/
say @.1 /*show the first ITEM found. */
say @.1 /*show the first ITEM found. */
Line 1,850: Line 1,850:
parser: parse arg yy,tail,,@. @@. @@@; $$=$; @L=9; yb='<'yy; ye='</'yy">"
parser: parse arg yy,tail,,@. @@. @@@; $$=$; @L=9; yb='<'yy; ye='</'yy">"
tail=word(tail 1, 1) /*use a tail ">" or not?*/
tail=word(tail 1, 1) /*use a tail ">" or not?*/
do #=1 until $$='' /*parse complete XML doc*/
do #=1 until $$='' /*parse complete XML doc*/
if tail then parse var $$ (yb) '>' @@.# (ye) $$ /*find meat*/
if tail then parse var $$ (yb) '>' @@.# (ye) $$ /*find meat*/
else parse var $$ (yb) @@.# (ye) $$ /* " " */
else parse var $$ (yb) @@.# (ye) $$ /* " " */
@.#=space(@@.#); @@@=space(@@@ @.#) /*shrink; @@@=list of YY*/
@.#=space(@@.#); @@@=space(@@@ @.#) /*shrink; @@@=list of YY*/
@L.#=length(@.#); @L=max(@L,@L.#) /*YY length, max length.*/
@L.#=length(@.#); @L=max(@L,@L.#) /*YY length, max length.*/
end /*#*/
end /*#*/
#=#-1 /*adjust # things found.*/
#=#-1 /*adjust # things found.*/
return</lang>
return</lang>