Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
36
Task/XML-XPath/REXX/xml-xpath-1.rexx
Normal file
36
Task/XML-XPath/REXX/xml-xpath-1.rexx
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/*REXX program to parse various queries on an XML document (from a file)*/
|
||||
iFID='XPATH.XML' /*name of the input XML file(doc)*/
|
||||
$= /*string will contain file's text*/
|
||||
do j=1 while lines(iFID)\==0 /*read the entire file into a str*/
|
||||
$=$ linein(iFID) /*append the line to the $ string*/
|
||||
end /*j*/
|
||||
/* [↓] show 1st ITEM in the doc*/
|
||||
parse var $ '<item ' item "</item>"
|
||||
say center('first item:',length(space(item)),'─') /*show a nice header*/
|
||||
say space(item)
|
||||
/* [↓] show all PRICES in the doc*/
|
||||
prices= /*nullify the list and add to it.*/
|
||||
$$=$ /*start with a fresh copy of doc.*/
|
||||
do until $$='' /* [↓] keep parsing until done. */
|
||||
parse var $$ '<price>' price '</price>' $$
|
||||
prices=prices price /*added the price to the list. */
|
||||
end /*until*/
|
||||
say
|
||||
say center('prices:',length(space(prices)),'─') /*show a nice header*/
|
||||
say space(prices)
|
||||
/* [↓] show all NAMES in the doc*/
|
||||
names.= /*nullify the list and add to it.*/
|
||||
L=length(' names: ') /*maximum length of any one name.*/
|
||||
$$=$ /*start with a fresh copy of doc.*/
|
||||
do #=1 until $$='' /* [↓] keep parsing until done. */
|
||||
parse var $$ '<name>' names.# '</name>' $$
|
||||
L=max(L,length(names.#)) /*used to find the widest name. */
|
||||
end /*#*/
|
||||
|
||||
names.0=#-1 /*adjust the # of names (DO loop)*/
|
||||
say
|
||||
say center('names:',L,'─') /*show a nicely formatted header.*/
|
||||
do k=1 for names.0 /*show all the names in the list.*/
|
||||
say names.k /*show a name from the NAMES list*/
|
||||
end /*k*/
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
34
Task/XML-XPath/REXX/xml-xpath-2.rexx
Normal file
34
Task/XML-XPath/REXX/xml-xpath-2.rexx
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/*REXX program to parse various queries on an XML document (from a file)*/
|
||||
iFID='XPATH.XML' /*name of the input XML file(doc)*/
|
||||
$= /*string will contain file's text*/
|
||||
do j=1 while lines(iFID)\==0 /*read the entire file into a str*/
|
||||
$=$ linein(iFID) /*append the line to the $ string*/
|
||||
end /*j*/
|
||||
|
||||
call parser 'item', 0 /*go and parse the all ITEMs. */
|
||||
say center('first item:',@L.1,'─') /*show a nicely formatted header.*/
|
||||
say @.1 /*show the first ITEM found. */
|
||||
say
|
||||
|
||||
call parser 'price' /*go and parse all the PRICEs. */
|
||||
say center('prices:',length(@@@),'─') /*show a nicely formatted header.*/
|
||||
say @@@ /*show a list of all the prices. */
|
||||
say
|
||||
|
||||
call parser 'name'
|
||||
say center('names:',@L,'─') /*show a nicely formatted header.*/
|
||||
do k=1 for # /*show all the names in the list.*/
|
||||
say @.k /*show a name from the NAMES list*/
|
||||
end /*k*/
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────PARSER subroutine───────────────────*/
|
||||
parser: parse arg yy,tail,,@. @@. @@@; $$=$; @L=9; yb='<'yy; ye='</'yy">"
|
||||
tail=word(tail 1, 1) /*use a tail ">" or not?*/
|
||||
do #=1 until $$='' /*parse complete XML doc*/
|
||||
if tail then parse var $$ (yb) '>' @@.# (ye) $$ /*find meat*/
|
||||
else parse var $$ (yb) @@.# (ye) $$ /* " " */
|
||||
@.#=space(@@.#); @@@=space(@@@ @.#) /*shrink; @@@=list of YY*/
|
||||
@L.#=length(@.#); @L=max(@L,@L.#) /*YY length, max length.*/
|
||||
end /*#*/
|
||||
#=#-1 /*adjust # things found.*/
|
||||
return
|
||||
Loading…
Add table
Add a link
Reference in a new issue