Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
35
Task/XML-XPath/REXX/xml-xpath-1.rexx
Normal file
35
Task/XML-XPath/REXX/xml-xpath-1.rexx
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/*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 the file's text. */
|
||||
do j=1 while lines(iFID)\==0 /*read the entire file into a string. */
|
||||
$=$ linein(iFID) /*append the line to the $ string. */
|
||||
end /*j*/
|
||||
/* [↓] show 1st ITEM in the document*/
|
||||
parse var $ '<item ' item "</item>"
|
||||
say center('first item:',length(space(item)),'─') /*display a nice header.*/
|
||||
say space(item)
|
||||
/* [↓] show all PRICES in the document*/
|
||||
prices= /*nullify the list and add/append to it*/
|
||||
$$=$ /*start with a fresh copy of document. */
|
||||
do until $$='' /* [↓] keep parsing string until done.*/
|
||||
parse var $$ '<price>' price '</price>' $$
|
||||
prices=prices price /*add/append the price to the list. */
|
||||
end /*until*/
|
||||
say
|
||||
say center('prices:',length(space(prices)),'─') /*display a nice header.*/
|
||||
say space(prices)
|
||||
/* [↓] show all NAMES in the document*/
|
||||
names.= /*nullify the list and add/append to it*/
|
||||
L=length(' names: ') /*maximum length of any one list name. */
|
||||
$$=$ /*start with a fresh copy of document. */
|
||||
do #=1 until $$='' /* [↓] keep parsing string until done.*/
|
||||
parse var $$ '<name>' names.# '</name>' $$
|
||||
L=max(L,length(names.#)) /*L: is used to find the widest name. */
|
||||
end /*#*/
|
||||
|
||||
names.0=#-1; say /*adjust the number of names (DO loop).*/
|
||||
say center('names:',L,'─') /*display a nicely formatted header. */
|
||||
do k=1 for names.0 /*display all the names in the list. */
|
||||
say names.k /*display a name from the NAMES list.*/
|
||||
end /*k*/
|
||||
/*stick a fork in it, we're all done. */
|
||||
32
Task/XML-XPath/REXX/xml-xpath-2.rexx
Normal file
32
Task/XML-XPath/REXX/xml-xpath-2.rexx
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/*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 the file's text. */
|
||||
do j=1 while lines(iFID)\==0 /*read the entire file into a string. */
|
||||
$=$ linein(iFID) /*append the line to the $ string. */
|
||||
end /*j*/
|
||||
/* [↓] display 1st ITEM in document. */
|
||||
call parser 'item', 0 /*go and parse the all the ITEMs. */
|
||||
say center('first item:',@L.1,'─') /*display a nicely formatted header. */
|
||||
say @.1; say /*display the first ITEM found. */
|
||||
|
||||
call parser 'price' /*go and parse all the PRICEs. */
|
||||
say center('prices:',length(@@@),'─') /*display a nicely formatted header. */
|
||||
say @@@; say /*display a list of all the prices. */
|
||||
|
||||
call parser 'name'
|
||||
say center('names:',@L,'─') /*display a nicely formatted header. */
|
||||
do k=1 for # /*display all the names in the list. */
|
||||
say @.k /*display a name from the NAMES list.*/
|
||||
end /*k*/
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*────────────────────────────────────────────────────────────────────────────*/
|
||||
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.#) /*length; maximum length. */
|
||||
end /*#*/
|
||||
#=#-1 /*adjust # of thing found.*/
|
||||
return
|
||||
Loading…
Add table
Add a link
Reference in a new issue