Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
28
Task/XML-XPath/CoffeeScript/xml-xpath-1.coffee
Normal file
28
Task/XML-XPath/CoffeeScript/xml-xpath-1.coffee
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
doc = new DOMParser().parseFromString '
|
||||
<inventory title="OmniCorp Store #45x10^3">
|
||||
<section name="health">
|
||||
<item upc="123456789" stock="12">
|
||||
<name>Invisibility Cream</name>
|
||||
<price>14.50</price>
|
||||
<description>Makes you invisible</description>
|
||||
</item>
|
||||
<item upc="445322344" stock="18">
|
||||
<name>Levitation Salve</name>
|
||||
<price>23.99</price>
|
||||
<description>Levitate yourself for up to 3 hours per application</description>
|
||||
</item>
|
||||
</section>
|
||||
<section name="food">
|
||||
<item upc="485672034" stock="653">
|
||||
<name>Blork and Freen Instameal</name>
|
||||
<price>4.95</price>
|
||||
<description>A tasty meal in a tablet; just add water</description>
|
||||
</item>
|
||||
<item upc="132957764" stock="44">
|
||||
<name>Grob winglets</name>
|
||||
<price>3.56</price>
|
||||
<description>Tender winglets of Grob. Just add water</description>
|
||||
</item>
|
||||
</section>
|
||||
</inventory>
|
||||
', 'text/xml'
|
||||
12
Task/XML-XPath/CoffeeScript/xml-xpath-2.coffee
Normal file
12
Task/XML-XPath/CoffeeScript/xml-xpath-2.coffee
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
# Retrieve the first "item" element
|
||||
doc.evaluate('//item', doc, {}, 7, {}).snapshotItem 0
|
||||
|
||||
# Perform an action on each "price" element (print it out)
|
||||
prices = doc.evaluate "//price", doc, {}, 7, {}
|
||||
for i in [0...prices.snapshotLength] by 1
|
||||
console.log prices.snapshotItem(i).textContent
|
||||
|
||||
# Get an array of all the "name" elements
|
||||
names = doc.evaluate "//name", doc, {}, 7, {}
|
||||
names = for i in [0...names.snapshotLength] by 1
|
||||
names.snapshotItem i
|
||||
|
|
@ -1,36 +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 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*/
|
||||
/*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 doc*/
|
||||
parse var $ '<item ' item "</item>"
|
||||
say center('first item:',length(space(item)),'─') /*show a nice header*/
|
||||
/* [↓] 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 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. */
|
||||
/* [↓] 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)),'─') /*show a nice header*/
|
||||
say center('prices:',length(space(prices)),'─') /*display 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. */
|
||||
/* [↓] 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 /*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*/
|
||||
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*/
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*stick a fork in it, we're all done. */
|
||||
|
|
|
|||
|
|
@ -1,34 +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 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*/
|
||||
/*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 '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 '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,'─') /*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.*/
|
||||
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 # things found.*/
|
||||
#=#-1 /*adjust # of thing found.*/
|
||||
return
|
||||
|
|
|
|||
29
Task/XML-XPath/VBScript/xml-xpath.vb
Normal file
29
Task/XML-XPath/VBScript/xml-xpath.vb
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
Set objXMLDoc = CreateObject("msxml2.domdocument")
|
||||
|
||||
objXMLDoc.load("In.xml")
|
||||
|
||||
Set item_nodes = objXMLDoc.selectNodes("//item")
|
||||
i = 1
|
||||
For Each item In item_nodes
|
||||
If i = 1 Then
|
||||
WScript.StdOut.Write item.xml
|
||||
WScript.StdOut.WriteBlankLines(2)
|
||||
Exit For
|
||||
End If
|
||||
Next
|
||||
|
||||
Set price_nodes = objXMLDoc.selectNodes("//price")
|
||||
list_price = ""
|
||||
For Each price In price_nodes
|
||||
list_price = list_price & price.text & ", "
|
||||
Next
|
||||
WScript.StdOut.Write list_price
|
||||
WScript.StdOut.WriteBlankLines(2)
|
||||
|
||||
Set name_nodes = objXMLDoc.selectNodes("//name")
|
||||
list_name = ""
|
||||
For Each name In name_nodes
|
||||
list_name = list_name & name.text & ", "
|
||||
Next
|
||||
WScript.StdOut.Write list_name
|
||||
WScript.StdOut.WriteBlankLines(2)
|
||||
Loading…
Add table
Add a link
Reference in a new issue