World: r3wp
[XML] xml related conversations
older newer | first last |
Graham 28-Jun-2009 [800x3] | cool .. |
creates a value element for each value :( | |
value?: | |
Sunanda 28-Jun-2009 [803] | As I said, you may need to tidy things up.....I wrote some code to do that, but it is hardwired for the particular dataset i was using. |
Graham 28-Jun-2009 [804x5] | Looks good ... I can cope :) |
fix-object: func [ obj [object!] /local prev ][ foreach element next first obj [ if object? o: get in obj element [ ; is object, so check to see if has value? either "value?" = form next first o [ set in obj element trim/head/tail get in o 'value? ][ fix-object o ] ] ] ] this fixes up the object created by xml-to-object | |
ooops ... doesn't need the /loca | |
ie. should be /local o | |
or not | |
Sunanda 28-Jun-2009 [809] | Much neater than my hack! |
Graham 28-Jun-2009 [810x4] | I've only tested it once :) |
I've also noticed that xml-to-object has to be run on a copy .... it must alter the original data block it is fed | |
Proably the source of my earlier issues | |
Anyway this is looking promising. I can take an xml message, construct a rebol object from it ... rearrange bits to create a new object and then create a reply xml message. | |
Gabriele 29-Jun-2009 [814x2] | why not either in o 'value? ? |
you can add value? to /local and then do either value?: in o 'value? [ ... get value?] | |
Graham 29-Jun-2009 [816x3] | I think I tried either 'value? = next first o but I couldn't figure out why that didn't work ... |
Your suggestion looks good :) | |
I did want to make sure that value? was the first member of the object | |
Gabriele 29-Jun-2009 [819] | i see, your problem was that next first o is a block. if you also want to make sure there's nothing else in the object (but then... why is it an object?), you could check [value?] = next first o or [self value?] = first o |
Graham 29-Jun-2009 [820] | It's an object because xml-to-object creates them that way :( |
Graham 5-Jul-2009 [821x2] | If xml-to-object meets a xml file with a number of elements with the same name, it creates a block of objects. |
so, this is an attempt to remedy this fix-object: func [obj [object!] /local o value? ] [ foreach element next first obj [ if object? o: get in obj element [ ; is object, so check to see if has value? either value?: in o 'value? [ set in obj element trim/head/tail get value? ] [ fix-object o ] ] if block? o [ foreach ob o [ fix-object ob ] ] ] ] | |
CharlesW 1-Aug-2009 [823x3] | Folks, I have gone through this forum with the hopes that I woul''nt bother you with a newb style question. I have been trying all sorts of different xml libraries (rebelxml.r, xml-parse.r, xml-object.r) as well as a few others I found. No matter what I do, I can't seem to pull the values I need. |
Here is the snipped of XMl: <?xml version="1.0"?> <xts:sports-content-set xmlns:xts="http://www.xmlteam.com"query-date-time="20090724T011802-0400" query-string="http://fod.xmlteam.com/api-trial/getDocuments?doc-ids=xt.9140271-box" hostname="fod.xmlteam.com" result-count="1" error-count="0" elapsed-time="64.2ms"><sports-content xmlns:str="java.lang.String" xmlns:dt="http://xsltsl.org/date-time" xmlns:xts="http://www.xmlteam.com"xmlns:exsl="http://exslt.org/common" path-id="baseball/l.mlb.com/event-summary/xt.9140271-box" xts:systemid="MLB_Boxscore_XML" xts:tsnid="9140271"> <sports-metadata xmlns:fs="java.io.File" date-time="20090323T193000-0400" doc-id="xt.9140271-box" xts:tsnslug="AAX%BOX-LOS-ANA" language="en-US" revision-id="l.mlb.com-2009-e.26882-event-stats-sportsnetwork.com" fixture-key="event-stats" document-class="event-summary" fixture-name="Box Score"> <sports-title>Boxscore: LA Angels vs. Los Angeles</sports-title> <sports-content-codes> <sports-content-code code-name="The Sports Network" code-key="sportsnetwork.com" code-type="publisher"/> <sports-content-code code-name="XML Team Solutions, Inc." code-key="xmlteam.com" code-type="distributor"/> <sports-content-code code-type="sport" code-key="15007000" code-name="Baseball"/> <sports-content-code code-type="league" code-key="l.mlb.com" code-name="Major League Baseball"/> <sports-content-code code-type="season-type" code-key="pre-season"/> <sports-content-code code-type="season" code-key="2009"/> <sports-content-code code-type="priority" code-key="normal"/> <sports-content-code code-type="conference" code-key="c.national" code-name="National"/> <sports-content-code code-type="conference" code-key="c.american" code-name="American"/> <sports-content-code code-type="team" code-key="l.mlb.com-t.11" code-name="Los Angeles Angels"/> <sports-content-code code-type="team" code-key="l.mlb.com-t.28" code-name="Los Angeles Dodgers"/> <sports-content-code code-type="action-listing" code-key="complete"/> </sports-content-codes> </sports-metadata> <sports-event xmlns:fs="java.io.File"> <event-metadata xmlns:xte="www.xmlteam.com/xte" date-coverage-type="event" event-key="l.mlb.com-2009-e.26882" date-coverage-value="l.mlb.com-2009-e.26882" event-status="post-event" duration="2:58" start-date-time="20090323T160500-0400" xts:game-of-day="1"> <sports-content-codes/> <event-metadata-baseball/> <site> <site-metadata> <home-location/> </site-metadata> <site-stats attendance="8704"/> </site> </event-metadata> <team> <team-metadata team-key="l.mlb.com-t.28" alignment="away"> <name first="Los Angeles" last="Dodgers"/> </team-metadata> <team-stats score="4" score-opposing="10" event-outcome="loss"> <sub-score period-value="1" score="1"/> <sub-score period-value="2" score="0"/> <sub-score period-value="3" score="0"/> <sub-score period-value="4" score="3"/> <sub-score period-value="5" score="0"/> <sub-score period-value="6" score="0"/> <sub-score period-value="7" score="0"/> <sub-score period-value="8" score="0"/> <sub-score period-value="9" score="0"/> <team-stats-baseball> <stats-baseball-offensive runs-scored="4" at-bats="36" hits="9" rbi="4" bases-on-balls="2" strikeouts="4" doubles="0" triples="0" home-runs="0" grand-slams="0" sac-flies="0" sacrifices="0" grounded-into-double-play="1" stolen-bases="1" stolen-bases-caught="1" hit-by-pitch="0" left-on-base="7"/> <stats-baseball-defensive errors="0" errors-passed-ball="0"/> <stats-baseball-pitching runs-allowed="10" hits="13" earned-runs="10" bases-on-balls="6" strikeouts="8" era="10.000" balks="0" errors-wild-pitch="0" number-of-pitches="0" number-of-strikes="0" shutouts="0" games-complete="0" wins="0" losses="1"/> </team-stats-baseball> </team-stats> <player id="b.11965"> <player-metadata position-event="8" player-key="l.mlb.com-p.11965" status="starter"> <name first="Matt" last="Kemp"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-offensive runs-scored="0" at-bats="4" hits="1" rbi="2" bases-on-balls="0" strikeouts="0" singles="1" doubles="0" triples="0" home-runs="0" grand-slams="0" sac-flies="0" sacrifices="0" grounded-into-double-play="0" stolen-bases="0" stolen-bases-caught="1" hit-by-pitch="0" average=".271"/> <stats-baseball-defensive errors="0" errors-passed-ball="0"/> </player-stats-baseball> </player-stats> </player> | |
Using rebelxml.r I have tried: get-xml-data/content/with-attribute 'xts:sports-content-set/sports-content/sports-metadata/sports-content-codes '/sports-content-code/code-type "sport" and many variations of this statement. Using: obj-xml I have tried variations of obj-xml/document/xts-sports-content-set/sports-content/sports-metadata/sports-content-codes/sports-content-code/value? As an example I tried to pull out the league information but could not, However I was able to pull out the TITLE using obj-xml/document/xts-sports-content-set/sports-content/sports-metadata/ sports-title/value? Obviously, I am clueless, so if anyone can point me in the right direction for a well document library (Hopefully with examples) that would be great. Otherwise if there is something glaring that I am doing wrong, please let me know. Thanks, Charlie | |
Graham 1-Aug-2009 [826] | Rebol's open source xml parsers are not fully complete. Where is the full XML file that the fragment comes from? |
CharlesW 1-Aug-2009 [827x2] | I<?xml version="1.0"?> <xts:sports-content-set xmlns:xts="http://www.xmlteam.com"query-date-time="20090724T011802-0400" query-string="http://fod.xmlteam.com/api-trial/getDocuments?doc-ids=xt.9140271-box" hostname="fod.xmlteam.com" result-count="1" error-count="0" elapsed-time="64.2ms"><sports-content xmlns:str="java.lang.String" xmlns:dt="http://xsltsl.org/date-time" xmlns:xts="http://www.xmlteam.com"xmlns:exsl="http://exslt.org/common" path-id="baseball/l.mlb.com/event-summary/xt.9140271-box" xts:systemid="MLB_Boxscore_XML" xts:tsnid="9140271"> <sports-metadata xmlns:fs="java.io.File" date-time="20090323T193000-0400" doc-id="xt.9140271-box" xts:tsnslug="AAX%BOX-LOS-ANA" language="en-US" revision-id="l.mlb.com-2009-e.26882-event-stats-sportsnetwork.com" fixture-key="event-stats" document-class="event-summary" fixture-name="Box Score"> <sports-title>Boxscore: LA Angels vs. Los Angeles</sports-title> <sports-content-codes> <sports-content-code code-name="The Sports Network" code-key="sportsnetwork.com" code-type="publisher"/> <sports-content-code code-name="XML Team Solutions, Inc." code-key="xmlteam.com" code-type="distributor"/> <sports-content-code code-type="sport" code-key="15007000" code-name="Baseball"/> <sports-content-code code-type="league" code-key="l.mlb.com" code-name="Major League Baseball"/> <sports-content-code code-type="season-type" code-key="pre-season"/> <sports-content-code code-type="season" code-key="2009"/> <sports-content-code code-type="priority" code-key="normal"/> <sports-content-code code-type="conference" code-key="c.national" code-name="National"/> <sports-content-code code-type="conference" code-key="c.american" code-name="American"/> <sports-content-code code-type="team" code-key="l.mlb.com-t.11" code-name="Los Angeles Angels"/> <sports-content-code code-type="team" code-key="l.mlb.com-t.28" code-name="Los Angeles Dodgers"/> <sports-content-code code-type="action-listing" code-key="complete"/> </sports-content-codes> </sports-metadata> <sports-event xmlns:fs="java.io.File"> <event-metadata xmlns:xte="www.xmlteam.com/xte" date-coverage-type="event" event-key="l.mlb.com-2009-e.26882" date-coverage-value="l.mlb.com-2009-e.26882" event-status="post-event" duration="2:58" start-date-time="20090323T160500-0400" xts:game-of-day="1"> <sports-content-codes/> <event-metadata-baseball/> <site> <site-metadata> <home-location/> </site-metadata> <site-stats attendance="8704"/> </site> </event-metadata> <team> <team-metadata team-key="l.mlb.com-t.28" alignment="away"> <name first="Los Angeles" last="Dodgers"/> </team-metadata> <team-stats score="4" score-opposing="10" event-outcome="loss"> <sub-score period-value="1" score="1"/> <sub-score period-value="2" score="0"/> <sub-score period-value="3" score="0"/> <sub-score period-value="4" score="3"/> <sub-score period-value="5" score="0"/> <sub-score period-value="6" score="0"/> <sub-score period-value="7" score="0"/> <sub-score period-value="8" score="0"/> <sub-score period-value="9" score="0"/> <team-stats-baseball> <stats-baseball-offensive runs-scored="4" at-bats="36" hits="9" rbi="4" bases-on-balls="2" strikeouts="4" doubles="0" triples="0" home-runs="0" grand-slams="0" sac-flies="0" sacrifices="0" grounded-into-double-play="1" stolen-bases="1" stolen-bases-caught="1" hit-by-pitch="0" left-on-base="7"/> <stats-baseball-defensive errors="0" errors-passed-ball="0"/> <stats-baseball-pitching runs-allowed="10" hits="13" earned-runs="10" bases-on-balls="6" strikeouts="8" era="10.000" balks="0" errors-wild-pitch="0" number-of-pitches="0" number-of-strikes="0" shutouts="0" games-complete="0" wins="0" losses="1"/> </team-stats-baseball> </team-stats> <player id="b.11965"> <player-metadata position-event="8" player-key="l.mlb.com-p.11965" status="starter"> <name first="Matt" last="Kemp"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-offensive runs-scored="0" at-bats="4" hits="1" rbi="2" bases-on-balls="0" strikeouts="0" singles="1" doubles="0" triples="0" home-runs="0" grand-slams="0" sac-flies="0" sacrifices="0" grounded-into-double-play="0" stolen-bases="0" stolen-bases-caught="1" hit-by-pitch="0" average=".271"/> <stats-baseball-defensive errors="0" errors-passed-ball="0"/> </player-stats-baseball> </player-stats> </player> <player id="b.7103"> <player-metadata position-event="8" player-key="l.mlb.com-p.7103" status="bench"> <name first="Jason" last="Repko"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-offensive runs-scored="0" at-bats="1" hits="0" rbi="0" bases-on-balls="0" strikeouts="0" singles="0" doubles="0" triples="0" home-runs="0" grand-slams="0" sac-flies="0" sacrifices="0" grounded-into-double-play="0" stolen-bases="0" stolen-bases-caught="0" hit-by-pitch="0" average=".219"/> <stats-baseball-defensive errors="0" errors-passed-ball="0"/> </player-stats-baseball> </player-stats> </player> <player id="b.9917"> <player-metadata position-event="9" player-key="l.mlb.com-p.9917" status="starter"> <name first="Andre" last="Ethier"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-offensive runs-scored="1" at-bats="3" hits="2" rbi="0" bases-on-balls="1" strikeouts="0" singles="2" doubles="0" triples="0" home-runs="0" grand-slams="0" sac-flies="0" sacrifices="0" grounded-into-double-play="0" stolen-bases="0" stolen-bases-caught="0" hit-by-pitch="0" average=".204"/> <stats-baseball-defensive errors="0" errors-passed-ball="0"/> </player-stats-baseball> </player-stats> </player> <player id="b.6892"> <player-metadata position-event="pr,7" player-key="l.mlb.com-p.6892" status="bench"> <name first="John-Ford" last="Griffin"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-offensive runs-scored="0" at-bats="1" hits="0" rbi="0" bases-on-balls="0" strikeouts="1" singles="0" doubles="0" triples="0" home-runs="0" grand-slams="0" sac-flies="0" sacrifices="0" grounded-into-double-play="0" stolen-bases="0" stolen-bases-caught="0" hit-by-pitch="0" average=".000"/> <stats-baseball-defensive errors="0" errors-passed-ball="0"/> </player-stats-baseball> </player-stats> </player> <player id="b.3810"> <player-metadata position-event="dh" player-key="l.mlb.com-p.3810" status="starter"> <name first="Manny" last="Ramirez"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-offensive runs-scored="0" at-bats="3" hits="0" rbi="0" bases-on-balls="0" strikeouts="2" singles="0" doubles="0" triples="0" home-runs="0" grand-slams="0" sac-flies="0" sacrifices="0" grounded-into-double-play="1" stolen-bases="0" stolen-bases-caught="0" hit-by-pitch="0" average=".200"/> <stats-baseball-defensive errors="0" errors-passed-ball="0"/> </player-stats-baseball> </player-stats> </player> <player id="b.9776"> <player-metadata position-event="ph,dh" player-key="l.mlb.com-p.9776" status="bench"> <name first="A.J." last="Ellis"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-offensive runs-scored="0" at-bats="1" hits="1" rbi="0" bases-on-balls="0" strikeouts="0" singles="1" doubles="0" triples="0" home-runs="0" grand-slams="0" sac-flies="0" sacrifices="0" grounded-into-double-play="0" stolen-bases="0" stolen-bases-caught="0" hit-by-pitch="0" average=".320"/> <stats-baseball-defensive errors="0" errors-passed-ball="0"/> </player-stats-baseball> </player-stats> </player> <player id="b.6773"> <player-metadata position-event="3" player-key="l.mlb.com-p.6773" status="starter"> <name first="James" last="Loney"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-offensive runs-scored="0" at-bats="4" hits="1" rbi="0" bases-on-balls="0" strikeouts="0" singles="1" doubles="0" triples="0" home-runs="0" grand-slams="0" sac-flies="0" sacrifices="0" grounded-into-double-play="0" stolen-bases="0" stolen-bases-caught="0" hit-by-pitch="0" average=".241"/> <stats-baseball-defensive errors="0" errors-passed-ball="0"/> </player-stats-baseball> </player-stats> </player> <player id="b.5664"> <player-metadata position-event="3" player-key="l.mlb.com-p.5664" status="bench"> <name first="Doug" last="Mientkiewicz"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-offensive runs-scored="0" at-bats="0" hits="0" rbi="0" bases-on-balls="0" strikeouts="0" singles="0" doubles="0" triples="0" home-runs="0" grand-slams="0" sac-flies="0" sacrifices="0" grounded-into-double-play="0" stolen-bases="0" stolen-bases-caught="0" hit-by-pitch="0" average=".238"/> <stats-baseball-defensive errors="0" errors-passed-ball="0"/> </player-stats-baseball> </player-stats> </player> <player id="b.13237"> <player-metadata position-event="2" player-key="l.mlb.com-p.13237" status="starter"> <name first="Russell" last="Martin"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-offensive runs-scored="1" at-bats="3" hits="2" rbi="1" bases-on-balls="0" strikeouts="0" singles="2" doubles="0" triples="0" home-runs="0" grand-slams="0" sac-flies="0" sacrifices="0" grounded-into-double-play="0" stolen-bases="1" stolen-bases-caught="0" hit-by-pitch="0" average=".394"/> <stats-baseball-defensive errors="0" errors-passed-ball="0"/> </player-stats-baseball> </player-stats> </player> <player id="b.7897"> <player-metadata position-event="2" player-key="l.mlb.com-p.7897" status="bench"> <name first="Danny" last="Ardoin"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-offensive runs-scored="0" at-bats="1" hits="0" rbi="0" bases-on-balls="0" strikeouts="0" singles="0" doubles="0" triples="0" home-runs="0" grand-slams="0" sac-flies="0" sacrifices="0" grounded-into-double-play="0" stolen-bases="0" stolen-bases-caught="0" hit-by-pitch="0" average=".375"/> <stats-baseball-defensive errors="0" errors-passed-ball="0"/> </player-stats-baseball> </player-stats> </player> <player id="b.2687"> <player-metadata position-event="5" player-key="l.mlb.com-p.2687" status="starter"> <name first="Mark" last="Loretta"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-offensive runs-scored="0" at-bats="2" hits="0" rbi="0" bases-on-balls="0" strikeouts="0" singles="0" doubles="0" triples="0" home-runs="0" grand-slams="0" sac-flies="0" sacrifices="0" grounded-into-double-play="0" stolen-bases="0" stolen-bases-caught="0" hit-by-pitch="0" average=".250"/> <stats-baseball-defensive errors="0" errors-passed-ball="0"/> </player-stats-baseball> </player-stats> </player> <player id="b.14163"> <player-metadata position-event="5" player-key="l.mlb.com-p.14163" status="bench"> <name first="Luis" last="Maza"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-offensive runs-scored="0" at-bats="2" hits="1" rbi="0" bases-on-balls="0" strikeouts="0" singles="1" doubles="0" triples="0" home-runs="0" grand-slams="0" sac-flies="0" sacrifices="0" grounded-into-double-play="0" stolen-bases="0" stolen-bases-caught="0" hit-by-pitch="0" average=".100"/> <stats-baseball-defensive errors="0" errors-passed-ball="0"/> </player-stats-baseball> </player-stats> </player> <player id="b.17507"> <player-metadata position-event="4" player-key="l.mlb.com-p.17507" status="starter"> <name first="Blake" last="DeWitt"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-offensive runs-scored="0" at-bats="2" hits="0" rbi="0" bases-on-balls="0" strikeouts="1" singles="0" doubles="0" triples="0" home-runs="0" grand-slams="0" sac-flies="0" sacrifices="0" grounded-into-double-play="0" stolen-bases="0" stolen-bases-caught="0" hit-by-pitch="0" average=".288"/> <stats-baseball-defensive errors="0" errors-passed-ball="0"/> </player-stats-baseball> </player-stats> </player> <player id="b.1347"> <player-metadata position-event="4" player-key="l.mlb.com-p.1347" status="bench"> <name first="Juan" last="Castro"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-offensive runs-scored="0" at-bats="2" hits="0" rbi="0" bases-on-balls="0" strikeouts="0" singles="0" doubles="0" triples="0" home-runs="0" grand-slams="0" sac-flies="0" sacrifices="0" grounded-into-double-play="0" stolen-bases="0" stolen-bases-caught="0" hit-by-pitch="0" average=".436"/> <stats-baseball-defensive errors="0" errors-passed-ball="0"/> </player-stats-baseball> </player-stats> </player> <player id="b.14313"> <player-metadata position-event="7,9" player-key="l.mlb.com-p.14313" status="starter"> <name first="Xavier" last="Paul"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-offensive runs-scored="1" at-bats="3" hits="0" rbi="0" bases-on-balls="1" strikeouts="0" singles="0" doubles="0" triples="0" home-runs="0" grand-slams="0" sac-flies="0" sacrifices="0" grounded-into-double-play="0" stolen-bases="0" stolen-bases-caught="0" hit-by-pitch="0" average=".383"/> <stats-baseball-defensive errors="0" errors-passed-ball="0"/> </player-stats-baseball> </player-stats> </player> <player id="b.18742"> <player-metadata position-event="6" player-key="l.mlb.com-p.18742" status="starter"> <name first="Chin-Lung" last="Hu"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-offensive runs-scored="1" at-bats="4" hits="1" rbi="1" bases-on-balls="0" strikeouts="0" singles="1" doubles="0" triples="0" home-runs="0" grand-slams="0" sac-flies="0" sacrifices="0" grounded-into-double-play="0" stolen-bases="0" stolen-bases-caught="0" hit-by-pitch="0" average=".316"/> <stats-baseball-defensive errors="0" errors-passed-ball="0"/> </player-stats-baseball> </player-stats> </player> <player id="p.8512"> <player-metadata position-event="1" player-key="l.mlb.com-p.8512" status="starter"> <name first="Chad" last="Billingsley"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-pitching runs-allowed="4" innings-pitched="2" hits="4" earned-runs="4" bases-on-balls="3" strikeouts="2" era="6.35" balks="0" shutouts="0" errors-wild-pitch="0" number-of-pitches="0" number-of-strikes="0" wins="0" losses="0" saves-blown="0" saves="0" xts:wins-season="1" xts:losses-season="1" xts:saves-season="0" xts:saves-blown-season="0"/> </player-stats-baseball> </player-stats> </player> <player id="p.5381"> <player-metadata position-event="1" player-key="l.mlb.com-p.5381" status="bench"> <name first="Jeff" last="Weaver"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-pitching runs-allowed="2" innings-pitched="2" hits="3" earned-runs="2" bases-on-balls="0" strikeouts="2" era="7.88" balks="0" shutouts="0" errors-wild-pitch="0" number-of-pitches="0" number-of-strikes="0" wins="0" losses="1" saves-blown="0" saves="0" event-credit="loss" xts:wins-season="0" xts:losses-season="1" xts:saves-season="0" xts:saves-blown-season="0"/> </player-stats-baseball> </player-stats> </player> <player id="p.18258"> <player-metadata position-event="1" player-key="l.mlb.com-p.18258" status="bench"> <name first="Scott" last="Elbert"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-pitching runs-allowed="0" innings-pitched="1" hits="1" earned-runs="0" bases-on-balls="0" strikeouts="1" era="6.14" balks="0" shutouts="0" errors-wild-pitch="0" number-of-pitches="0" number-of-strikes="0" wins="0" losses="0" saves-blown="0" saves="0" xts:wins-season="1" xts:losses-season="0" xts:saves-season="0" xts:saves-blown-season="0"/> </player-stats-baseball> </player-stats> </player> <player id="p.7482"> <player-metadata position-event="1" player-key="l.mlb.com-p.7482" status="bench"> <name first="Erick" last="Threets"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-pitching runs-allowed="2" innings-pitched="1" hits="1" earned-runs="2" bases-on-balls="1" strikeouts="2" era="5.40" balks="0" shutouts="0" errors-wild-pitch="0" number-of-pitches="0" number-of-strikes="0" wins="0" losses="0" saves-blown="0" saves="0" xts:wins-season="0" xts:losses-season="0" xts:saves-season="0" xts:saves-blown-season="0"/> </player-stats-baseball> </player-stats> </player> <player id="p.19392"> <player-metadata position-event="1" player-key="l.mlb.com-p.19392" status="bench"> <name first="Ramon" last="Troncoso"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-pitching runs-allowed="2" innings-pitched="1" hits="3" earned-runs="2" bases-on-balls="1" strikeouts="0" era="7.88" balks="0" shutouts="0" errors-wild-pitch="0" number-of-pitches="0" number-of-strikes="0" wins="0" losses="0" saves-blown="0" saves="0" xts:wins-season="0" xts:losses-season="1" xts:saves-season="1" xts:saves-blown-season="0"/> </player-stats-baseball> </player-stats> </player> <player id="p.14165"> <player-metadata position-event="1" player-key="l.mlb.com-p.14165" status="finished"> <name first="Brian" last="Mazone"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-pitching runs-allowed="0" innings-pitched="1" hits="1" earned-runs="0" bases-on-balls="1" strikeouts="1" era="0.00" balks="0" shutouts="0" errors-wild-pitch="0" number-of-pitches="0" number-of-strikes="0" wins="0" losses="0" saves-blown="0" saves="0" xts:wins-season="0" xts:losses-season="0" xts:saves-season="1" xts:saves-blown-season="0"/> </player-stats-baseball> </player-stats> </player> </team> <team> <team-metadata team-key="l.mlb.com-t.11" alignment="home"> <name first="Los Angeles" last="Angels"/> </team-metadata> <team-stats score="10" score-opposing="4" event-outcome="win"> <sub-score period-value="1" score="2"/> <sub-score period-value="2" score="2"/> <sub-score period-value="3" score="0"/> <sub-score period-value="4" score="2"/> <sub-score period-value="5" score="0"/> <sub-score period-value="6" score="2"/> <sub-score period-value="7" score="2"/> <sub-score period-value="8" score="0"/> <sub-score period-value="9"/> <team-stats-baseball> <stats-baseball-offensive runs-scored="10" at-bats="34" hits="13" rbi="10" bases-on-balls="6" strikeouts="8" doubles="2" triples="1" home-runs="3" grand-slams="0" sac-flies="0" sacrifices="0" grounded-into-double-play="1" stolen-bases="0" stolen-bases-caught="2" hit-by-pitch="0" left-on-base="6"/> <stats-baseball-defensive errors="3" errors-passed-ball="0"/> <stats-baseball-pitching runs-allowed="4" hits="9" earned-runs="3" bases-on-balls="2" strikeouts="4" era="3.000" balks="0" errors-wild-pitch="0" number-of-pitches="0" number-of-strikes="0" shutouts="0" games-complete="0" wins="1" losses="0"/> </team-stats-baseball> </team-stats> <player id="b.6445"> <player-metadata position-event="5" player-key="l.mlb.com-p.6445" status="starter"> <name first="Chone" last="Figgins"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-offensive runs-scored="0" at-bats="2" hits="1" rbi="1" bases-on-balls="1" strikeouts="0" singles="1" doubles="0" triples="0" home-runs="0" grand-slams="0" sac-flies="0" sacrifices="0" grounded-into-double-play="0" stolen-bases="0" stolen-bases-caught="2" hit-by-pitch="0" average=".325"/> <stats-baseball-defensive errors="0" errors-passed-ball="0"/> </player-stats-baseball> </player-stats> </player> <player id="b.20376"> <player-metadata position-event="ph,8" player-key="l.mlb.com-p.20376" status="bench"> <name first="Coby" last="Smith"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-offensive runs-scored="0" at-bats="2" hits="1" rbi="0" bases-on-balls="0" strikeouts="1" singles="1" doubles="0" triples="0" home-runs="0" grand-slams="0" sac-flies="0" sacrifices="0" grounded-into-double-play="0" stolen-bases="0" stolen-bases-caught="0" hit-by-pitch="0" average=".667"/> <stats-baseball-defensive errors="0" errors-passed-ball="0"/> </player-stats-baseball> </player-stats> </player> <player id="b.11967"> <player-metadata position-event="4" player-key="l.mlb.com-p.11967" status="starter"> <name first="Howie" last="Kendrick"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-offensive runs-scored="0" at-bats="2" hits="0" rbi="0" bases-on-balls="1" strikeouts="2" singles="0" doubles="0" triples="0" home-runs="0" grand-slams="0" sac-flies="0" sacrifices="0" grounded-into-double-play="0" stolen-bases="0" stolen-bases-caught="0" hit-by-pitch="0" average=".344"/> <stats-baseball-defensive errors="0" errors-passed-ball="0"/> </player-stats-baseball> </player-stats> </player> <player id="b.7011"> <player-metadata position-event="ph,2" player-key="l.mlb.com-p.7011" status="bench"> <name first="Ryan" last="Budde"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-offensive runs-scored="0" at-bats="1" hits="0" rbi="0" bases-on-balls="1" strikeouts="1" singles="0" doubles="0" triples="0" home-runs="0" grand-slams="0" sac-flies="0" sacrifices="0" grounded-into-double-play="0" stolen-bases="0" stolen-bases-caught="0" hit-by-pitch="0" average=".412"/> <stats-baseball-defensive errors="0" errors-passed-ball="0"/> </player-stats-baseball> </player-stats> </player> <player id="b.5533"> <player-metadata position-event="7" player-key="l.mlb.com-p.5533" status="starter"> <name first="Bobby" last="Abreu"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-offensive runs-scored="1" at-bats="2" hits="0" rbi="0" bases-on-balls="1" strikeouts="2" singles="0" doubles="0" triples="0" home-runs="0" grand-slams="0" sac-flies="0" sacrifices="0" grounded-into-double-play="0" stolen-bases="0" stolen-bases-caught="0" hit-by-pitch="0" average=".263"/> <stats-baseball-defensive errors="0" errors-passed-ball="0"/> </player-stats-baseball> </player-stats> </player> <player id="b.11570"> <player-metadata position-event="5" player-key="l.mlb.com-p.11570" status="bench"> <name first="Brandon" last="Wood"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-offensive runs-scored="1" at-bats="2" hits="1" rbi="0" bases-on-balls="0" strikeouts="0" singles="1" doubles="0" triples="0" home-runs="0" grand-slams="0" sac-flies="0" sacrifices="0" grounded-into-double-play="1" stolen-bases="0" stolen-bases-caught="0" hit-by-pitch="0" average=".354"/> <stats-baseball-defensive errors="1" errors-passed-ball="0"/> </player-stats-baseball> </player-stats> </player> <player id="b.1946"> <player-metadata position-event="9" player-key="l.mlb.com-p.1946" status="starter"> <name first="Vladimir" last="Guerrero"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-offensive runs-scored="1" at-bats="3" hits="2" rbi="0" bases-on-balls="0" strikeouts="0" singles="2" doubles="0" triples="0" home-runs="0" grand-slams="0" sac-flies="0" sacrifices="0" grounded-into-double-play="0" stolen-bases="0" stolen-bases-caught="0" hit-by-pitch="0" average=".250"/> <stats-baseball-defensive errors="0" errors-passed-ball="0"/> </player-stats-baseball> </player-stats> </player> <player id="b.19314"> <player-metadata position-event="9" player-key="l.mlb.com-p.19314" status="bench"> <name first="Chris" last="Pettit"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-offensive runs-scored="0" at-bats="2" hits="1" rbi="0" bases-on-balls="0" strikeouts="1" singles="1" doubles="0" triples="0" home-runs="0" grand-slams="0" sac-flies="0" sacrifices="0" grounded-into-double-play="0" stolen-bases="0" stolen-bases-caught="0" hit-by-pitch="0" average=".354"/> <stats-baseball-defensive errors="0" errors-passed-ball="0"/> </player-stats-baseball> </player-stats> </player> <player id="b.2062"> <player-metadata position-event="8" player-key="l.mlb.com-p.2062" status="starter"> <name first="Torii" last="Hunter"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-offensive runs-scored="0" at-bats="3" hits="1" rbi="2" bases-on-balls="0" strikeouts="0" singles="0" doubles="0" triples="1" home-runs="0" grand-slams="0" sac-flies="0" sacrifices="0" grounded-into-double-play="0" stolen-bases="0" stolen-bases-caught="0" hit-by-pitch="0" average=".182"/> <stats-baseball-defensive errors="1" errors-passed-ball="0"/> </player-stats-baseball> </player-stats> </player> <player id="b.15871"> <player-metadata position-event="4" player-key="l.mlb.com-p.15871" status="bench"> <name first="Sean" last="Rodriguez"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-offensive runs-scored="0" at-bats="1" hits="0" rbi="0" bases-on-balls="0" strikeouts="0" singles="0" doubles="0" triples="0" home-runs="0" grand-slams="0" sac-flies="0" sacrifices="0" grounded-into-double-play="0" stolen-bases="0" stolen-bases-caught="0" hit-by-pitch="0" average=".282"/> <stats-baseball-defensive errors="0" errors-passed-ball="0"/> </player-stats-baseball> </player-stats> </player> <player id="b.18447"> <player-metadata position-event="3" player-key="l.mlb.com-p.18447" status="starter"> <name first="Kendry" last="Morales"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-offensive runs-scored="0" at-bats="3" hits="0" rbi="0" bases-on-balls="0" strikeouts="0" singles="0" doubles="0" triples="0" home-runs="0" grand-slams="0" sac-flies="0" sacrifices="0" grounded-into-double-play="0" stolen-bases="0" stolen-bases-caught="0" hit-by-pitch="0" average=".367"/> <stats-baseball-defensive errors="0" errors-passed-ball="0"/> </player-stats-baseball> </player-stats> </player> <player id="b.7262"> <player-metadata position-event="3" player-key="l.mlb.com-p.7262" status="bench"> <name first="Matthew" last="Brown"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-offensive runs-scored="1" at-bats="1" hits="0" rbi="1" bases-on-balls="0" strikeouts="0" singles="0" doubles="0" triples="0" home-runs="0" grand-slams="0" sac-flies="0" sacrifices="0" grounded-into-double-play="0" stolen-bases="0" stolen-bases-caught="0" hit-by-pitch="0" average=".550"/> <stats-baseball-defensive errors="0" errors-passed-ball="0"/> </player-stats-baseball> </player-stats> </player> <player id="b.6012"> <player-metadata position-event="dh" player-key="l.mlb.com-p.6012" status="starter"> <name first="Juan" last="Rivera"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-offensive runs-scored="1" at-bats="2" hits="1" rbi="0" bases-on-balls="0" strikeouts="1" singles="0" doubles="1" triples="0" home-runs="0" grand-slams="0" sac-flies="0" sacrifices="0" grounded-into-double-play="0" stolen-bases="0" stolen-bases-caught="0" hit-by-pitch="0" average=".211"/> <stats-baseball-defensive errors="0" errors-passed-ball="0"/> </player-stats-baseball> </player-stats> </player> <player id="b.5647"> <player-metadata position-event="ph,dh" player-key="l.mlb.com-p.5647" status="bench"> <name first="Gary" last="Matthews"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-offensive runs-scored="0" at-bats="1" hits="0" rbi="0" bases-on-balls="1" strikeouts="0" singles="0" doubles="0" triples="0" home-runs="0" grand-slams="0" sac-flies="0" sacrifices="0" grounded-into-double-play="0" stolen-bases="0" stolen-bases-caught="0" hit-by-pitch="0" average=".357"/> <stats-baseball-defensive errors="0" errors-passed-ball="0"/> </player-stats-baseball> </player-stats> </player> <player id="b.6928"> <player-metadata position-event="2" player-key="l.mlb.com-p.6928" status="starter"> <name first="Jeff" last="Mathis"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-offensive runs-scored="1" at-bats="2" hits="1" rbi="1" bases-on-balls="0" strikeouts="0" singles="0" doubles="0" triples="0" home-runs="1" grand-slams="0" sac-flies="0" sacrifices="0" grounded-into-double-play="0" stolen-bases="0" stolen-bases-caught="0" hit-by-pitch="0" average=".343"/> <stats-baseball-defensive errors="0" errors-passed-ball="0"/> </player-stats-baseball> </player-stats> </player> <player id="b.6814"> <player-metadata position-event="ph,6" player-key="l.mlb.com-p.6814" status="bench"> <name first="Maicer" last="Izturis"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-offensive runs-scored="1" at-bats="1" hits="1" rbi="1" bases-on-balls="1" strikeouts="0" singles="1" doubles="0" triples="0" home-runs="0" grand-slams="0" sac-flies="0" sacrifices="0" grounded-into-double-play="0" stolen-bases="0" stolen-bases-caught="0" hit-by-pitch="0" average=".278"/> <stats-baseball-defensive errors="0" errors-passed-ball="0"/> </player-stats-baseball> </player-stats> </player> <player id="b.8016"> <player-metadata position-event="6" player-key="l.mlb.com-p.8016" status="starter"> <name first="Erick" last="Aybar"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-offensive runs-scored="2" at-bats="2" hits="2" rbi="2" bases-on-balls="0" strikeouts="0" singles="0" doubles="1" triples="0" home-runs="1" grand-slams="0" sac-flies="0" sacrifices="0" grounded-into-double-play="0" stolen-bases="0" stolen-bases-caught="0" hit-by-pitch="0" average=".310"/> <stats-baseball-defensive errors="1" errors-passed-ball="0"/> </player-stats-baseball> </player-stats> </player> <player id="b.6589"> <player-metadata position-event="ph,7" player-key="l.mlb.com-p.6589" status="bench"> <name first="Robb" last="Quinlan"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-offensive runs-scored="1" at-bats="2" hits="1" rbi="2" bases-on-balls="0" strikeouts="0" singles="0" doubles="0" triples="0" home-runs="1" grand-slams="0" sac-flies="0" sacrifices="0" grounded-into-double-play="0" stolen-bases="0" stolen-bases-caught="0" hit-by-pitch="0" average=".310"/> <stats-baseball-defensive errors="0" errors-passed-ball="0"/> </player-stats-baseball> </player-stats> </player> <player id="p.7092"> <player-metadata position-event="1" player-key="l.mlb.com-p.7092" status="starter"> <name first="Dustin" last="Moseley"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-pitching runs-allowed="4" innings-pitched="6" hits="8" earned-runs="3" bases-on-balls="1" strikeouts="3" era="3.15" balks="0" shutouts="0" errors-wild-pitch="0" number-of-pitches="0" number-of-strikes="0" wins="1" losses="0" saves-blown="0" saves="0" event-credit="win" xts:wins-season="3" xts:losses-season="0" xts:saves-season="0" xts:saves-blown-season="0"/> </player-stats-baseball> </player-stats> </player> <player id="p.20390"> <player-metadata position-event="1" player-key="l.mlb.com-p.20390" status="bench"> <name first="Trevor" last="Reckling"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-pitching runs-allowed="0" innings-pitched="2" hits="1" earned-runs="0" bases-on-balls="1" strikeouts="0" era="0.00" balks="0" shutouts="0" errors-wild-pitch="0" number-of-pitches="0" number-of-strikes="0" wins="0" losses="0" saves-blown="0" saves="0" xts:wins-season="0" xts:losses-season="0" xts:saves-season="0" xts:saves-blown-season="0"/> </player-stats-baseball> </player-stats> </player> <player id="p.20370"> <player-metadata position-event="1" player-key="l.mlb.com-p.20370" status="finished"> <name first="Mason" last="Tobin"/> </player-metadata> <player-stats> <player-stats-baseball> <stats-baseball-pitching runs-allowed="0" innings-pitched="1" hits="0" earned-runs="0" bases-on-balls="0" strikeouts="1" era="0.00" balks="0" shutouts="0" errors-wild-pitch="0" number-of-pitches="0" number-of-strikes="0" wins="0" losses="0" saves-blown="0" saves="0" xts:wins-season="0" xts:losses-season="0" xts:saves-season="0" xts:saves-blown-season="0"/> </player-stats-baseball> </player-stats> </player> </team> <officials> <official> <official-metadata position="Home Plate Umpire"> <name full="Jim Wolf"/> </official-metadata> </official> <official> <official-metadata position="First Base Umpire"> <name full="Bob Davidson"/> </official-metadata> </official> <official> <official-metadata position="Second Base Umpire"> <name full="Mike Winters"/> </official-metadata> </official> <official> <official-metadata position="Third Base Umpire"> <name full="Mike Everitt"/> </official-metadata> </official> </officials> <event-actions> <event-actions-baseball/> </event-actions> <highlight class="double-plays"> <p>Los Angeles 2; LA Angels 1.</p> </highlight> </sports-event> </sports-content></xts:sports-content-set> |
Is there a more sutiable language for parsing the XML? | |
Graham 2-Aug-2009 [829] | parse-xml and xml-to-object seems to work okay on this file. |
CharlesW 2-Aug-2009 [830] | It reads and parses ok. I get the block object but my problem is trying to access the individual elements. When venturing into some of the nested attributes, I just can't seem to get it returning a result.. Can you post an example on how you would retrieve the "hits" for <player id="b.11965"> or get the league info from sports-content-code code-type="league" |
Graham 2-Aug-2009 [831x4] | >> do %xml-parse.r Script: "A more XML 1.0 compliant set of XML parsing tools." (4-Dec-2001) >> do %xml-object.r Script: {Convert an XML-derived block structure into objects.} (29-Sep-2001) >> obj: first reduce xml-to-object parse-xml+ read %test.xml >> data: second obj == [make object! [ xts:sports-content-set: make object! [ sports-content: make object! [ sports... >> type? data == block! >> probe data/2/sports-content/sports-event/team/1/player/1 make object! [ player-metadata: make object! [ name: make object! [ value?: "" first: "Matt" last: "Kemp" ] position-event: "8" player-key: "l.mlb.com-p.11965" status: "starter" ] player-stats: make object! [ player-stats-baseball: make object! [ stats-baseball-offensive: make object! [ value?: "" runs-scored: "0" at-bats: "4" hits: "1" rbi: "2" bases-on-balls: "0" strikeouts: "0" singles: "1" doubles: "0" triples: "0" home-runs: "0" grand-slams: "0" sac-flies: "0" sacrifices: "0" grounded-into-double-play: "0" stolen-bases: "0" stolen-bases-caught: "1" hit-by-pitch: "0" average: ".271" ] stats-baseball-defensive: make object! [ value?: "" errors: "0" errors-passed-ball: "0" ] ] ] id: "b.11965" ] |
if you download anamonitor300.r, then you can browse the object like this mon data mon obj won't work because of the ":" in the object name | |
It should be easy enough to write a recurseive function that descends thru the object looking for some text, and then to print out the full path for you as in the recursive examples I posted above. | |
make that "straight forward" vs "easy" | |
CharlesW 2-Aug-2009 [835] | Thank you so much Graham, I will give it a try as you have indicated and will alsodownload anamonitor300.r |
Graham 2-Aug-2009 [836] | Good luck with this stuff .. it's pretty tedious navigating thru large objects like this ... |
Chris 12-Aug-2009 [837] | >> do http://www.ross-gill.com/r/altxml.r connecting to: www.ross-gill.com Script: "AltXML" (7-Jun-2009) >> all-stats: load-xml/dom your-xml-data >> player: stats/get-by-id "b.11965" >> his-stats: first player/get-by-tag <stats-baseball-offensive> >> his-stats/get #hits == "1" >> remove-each code codes: all-stats/get-by-tag <sports-content-code> ["league" <> code/get #code-type] == [make object! [ name: <sports-content-code> space: none value: [ #code-type "league" ... >> foreach code codes [probe code/get #code-name] Major ^/ League Baseball == "Major ^/ League Baseball" |
Graham 12-Aug-2009 [838] | How is your parser getting on these days? |
Chris 13-Aug-2009 [839] | Still seems to work as advertised - good for extraction; still missing the 'flatten function. Not much time for development in the schema direction though : ( |
Graham 13-Aug-2009 [840] | I'm guessing that it should be "all-stats/get-by-id" and not "stats/get-by-id" |
Graham 14-Aug-2009 [841] | Chris, do you documentation yet for your parser? |
Chris 14-Aug-2009 [842] | Doesn't go into much detail, but: http://www.ross-gill.com/page/XML+and+REBOL |
Graham 14-Aug-2009 [843x2] | Given some xml like this which is a list of documents http://code.google.com/apis/documents/docs/2.0/developers_guide_protocol.html#ListDocs how would your parser extract the <gd:resourceid> and text associated with these tags? |
again .. how would you use your parser to exxtract the <gd:resourceid> tags and associated text? | |
Chris 14-Aug-2009 [845x3] | >> google-xml: load-xml/dom clipboard:// ; copied from page >> entries: google-xml/get-by-tag <entry> == [make object! [ name: <entry> space: none value: [ #etag {"BxAUSh5RAyp7ImBq"} <... >> foreach entry entries [probe entry/get <resourceId>] spreadsheet:key == "spreadsheet:key" |
Note that while it appears namespaces have been stripped, they are in fact still there: | |
>> entry: first entries >> id: first entry/get-by-tag <resourceId> >> id/space == <gd> | |
Graham 14-Aug-2009 [848] | So, looks feasible to use your parser to create an api for googledocs ... |
Graham 15-Aug-2009 [849] | There's a rebzip script which has recently been updated on rebol.org which I guess can be used to open up docx |
older newer | first last |