REBOL3 - XML (xml related conversations [web-public])

Return to Index Page
Most recent messages (300 max) are listed first.

#UserMessageDate
867DockimbelIt's a matter of tradeoff, if you only need fast XML document reading, SAX is the winner. If you need to modify the document, you need DOM (with or without SAX).4-Jan-10 11:16
866PekrI like SAX model, because IIRC it allows to work on things in a "streamed" way, whereas DOM requires you load everything in memory? Sorry if I oversimpilifed it :-) IIRC Doc used such aproach in his Postgress SQL driver, in opposite to his mySQL one ...4-Jan-10 9:38
865BrianHThe semantic model of REBOL protocol schemes, implemented with the port! type, would fix well with the semantic model of SAX pull. SAX pull generates the same SAX events, except they are not propagated through callbacks - instead they are returned from function calls. SAX pull is sort of like an generator (in the Icon or Python sense) of SAX events. That is very similar in model to the behavior of command ports (like database ports).3-Jan-10 19:31
864JankoBrianH: What does that mean "port model"?3-Jan-10 13:52
863JankoRobert: it's a good idea but not for my case. I don't want the data strucure from whole xml , I want to stream it through parser and collect out the data. Geomol: I will look at it but probably not what I want in this particular case for the reason above Gregg: I haven't tested any yet, I googled and found that xml-parse.r above , which has sax style of work but seems huge. I only care to support the simplified subset of xml, xml with all the variants is a total bloat so I believe it can be that complex (and it doesn't support 100% of it also). Thats why I am considering writing a simple sax liek parser, I wrote it in c once and it was small (but it parsed even smaller subset of xml)3-Jan-10 13:51
862BrianHSAX pull parsing would work well with the port model.2-Jan-10 22:47
861GreggI believe Maarten has done a SAX style parser. I've used parse-xml in the past, sometimes post-processing the output to a different REBOL form, but my needs were simple.

Janko, have you tested any of the existing soluitions, with test input on target hardware, and found them to be too slow? If so, what were the results, and how fast do you need it to be?

2-Jan-10 22:44
860GeomolJanko, rebxml is a rebol version of xml. It can do the same things, but without the bad implementation, xml suffers from. The idea behind xml is ok, it's just not implemented well. Much of that is solved with the rebxml format.2-Jan-10 22:43
859RobertWouldn't it make a lot more sense to use a C based XML parser, construct a Rebol data-structure/string and return that to Rebol?2-Jan-10 22:36
858Jankothanks Geomol, I will study the links .. xml2rebxml seems short which is nice, but I haven't yet figured out what exactly rebxml is .. I am reading the first link you gave me2-Jan-10 22:24
857GeomolJanko, http://www.fys.ku.dk/~niclasen/rebxml/rebxml-spec.html http://www.rebol.org/view-script.r?script=xml2rebxml.r http://www.rebol.org/view-script.r?script=rebxml2xml.r2-Jan-10 22:08
856Jankoyes, I get a big xml made by "official" BLOATED standard for invoices .. I want to parse it as quick as possible and that's all2-Jan-10 22:07
855GrahamMine is a desktop application .. your needs for a web service differ ..2-Jan-10 21:54
854JankoI imagine that is too costly .. I preferr the callback model to just extract the relevant data out2-Jan-10 21:53
853GrahamYou can turn the xml file into a rebol object with it2-Jan-10 21:52
852GrahamYes, I have used it to parse large XML files2-Jan-10 21:52
851JankoI will need a xml parser .. I was thinkinf something fast and quick like sax style .. I found this one http://www.rebol.org/view-script.r?script=xml-parse.r but by looking of it it seems to offer a lot of things I don't need. Has anyone used it for "serrious" xml parsing with it. I am thinking of making my own simple minimal event based xml parser.2-Jan-10 19:22
850GrahamSounds like too much overhead ... unzip the docx, make changes to the xml portion and then rezip.15-Aug-09 9:56
849GrahamThere's a rebzip script which has recently been updated on rebol.org which I guess can be used to open up docx15-Aug-09 9:20
848GrahamSo, looks feasible to use your parser to create an api for googledocs ...15-Aug-09 1:23
847Chris>> entry: first entries >> id: first entry/get-by-tag <resourceId> >> id/space == <gd>15-Aug-09 0:59
846ChrisNote that while it appears namespaces have been stripped, they are in fact still there:15-Aug-09 0:57
845Chris>> 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"15-Aug-09 0:56
844Grahamagain .. how would you use your parser to exxtract the <gd:resourceid> tags and associated text?14-Aug-09 20:43
843GrahamGiven 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?14-Aug-09 20:42
842ChrisDoesn't go into much detail, but: http://www.ross-gill.com/page/XML+and+REBOL14-Aug-09 13:03
841GrahamChris, do you documentation yet for your parser?14-Aug-09 8:39
840GrahamI'm guessing that it should be "all-stats/get-by-id" and not "stats/get-by-id"14-Aug-09 1:41
839ChrisStill seems to work as advertised - good for extraction; still missing the 'flatten function. Not much time for development in the schema direction though : (13-Aug-09 12:20
838GrahamHow is your parser getting on these days?13-Aug-09 2:07
837Chris>> 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"

13-Aug-09 1:14
836GrahamGood luck with this stuff .. it's pretty tedious navigating thru large objects like this ...3-Aug-09 1:45
835CharlesWThank you so much Graham, I will give it a try as you have indicated and will alsodownload anamonitor300.r3-Aug-09 0:41
834Grahammake that "straight forward" vs "easy"2-Aug-09 21:06
833GrahamIt 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.2-Aug-09 21:04
832Grahamif 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

2-Aug-09 21:02
831Graham>> 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" ]2-Aug-09 20:59
830CharlesWIt 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"2-Aug-09 15:00
829Grahamparse-xml and xml-to-object seems to work okay on this file.2-Aug-09 4:37
828CharlesWIs there a more sutiable language for parsing the XML?2-Aug-09 1:56
827CharlesWI<?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>2-Aug-09 1:53
826GrahamRebol's open source xml parsers are not fully complete. Where is the full XML file that the fragment comes from?2-Aug-09 1:27
825CharlesWUsing 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

1-Aug-09 17:34
824CharlesWHere 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>1-Aug-09 17:25
823CharlesWFolks, 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.1-Aug-09 17:25
822Grahamso, 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 ] ] ] ]

6-Jul-09 0:09
821GrahamIf xml-to-object meets a xml file with a number of elements with the same name, it creates a block of objects.6-Jul-09 0:08
820GrahamIt's an object because xml-to-object creates them that way :(29-Jun-09 20:20
819Gabrielei 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 o29-Jun-09 10:57
818GrahamI did want to make sure that value? was the first member of the object29-Jun-09 10:20
817GrahamYour suggestion looks good :)29-Jun-09 10:17
816GrahamI think I tried

either 'value? = next first o

but I couldn't figure out why that didn't work ...

29-Jun-09 10:16
815Gabrieleyou can add value? to /local and then do either value?: in o 'value? [ ... get value?]29-Jun-09 9:14
814Gabrielewhy not either in o 'value? ?29-Jun-09 9:13
813GrahamAnyway 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.28-Jun-09 11:06
812GrahamProably the source of my earlier issues28-Jun-09 11:04
811GrahamI've also noticed that xml-to-object has to be run on a copy .... it must alter the original data block it is fed28-Jun-09 11:04
810GrahamI've only tested it once :)28-Jun-09 11:03
809SunandaMuch neater than my hack!28-Jun-09 11:01
808Grahamor not28-Jun-09 10:59
807Grahamie. should be /local o28-Jun-09 10:59
806Grahamooops ... doesn't need the /loca28-Jun-09 10:58
805Grahamfix-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

28-Jun-09 10:57
804GrahamLooks good ... I can cope :)28-Jun-09 9:44
803SunandaAs 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.28-Jun-09 9:35
802Grahamvalue?:28-Jun-09 9:13
801Grahamcreates a value element for each value :(28-Jun-09 9:12
800Grahamcool ..28-Jun-09 8:54
799Grahamoh ...sorry28-Jun-09 8:53
798GrahamHmm. There is no 'xml-object function28-Jun-09 8:52
797SunandaThis works for me: do %xml-object.r xml-file: read %my-xml-file.xml xml-object: first reduce xml-to-object parse-xml xml-file

Though the resulting object does need some tidying up

28-Jun-09 8:44
796GrahamI keep getting errors28-Jun-09 8:19
795GrahamGot a working example of their use?28-Jun-09 8:19
794SunandaBoth parse XML. The main difference is: -- xml-object.r uses REBOL's built-in mezzanine, parse-xml -- parse-xml.r is an improvement for parse-xml

In theory, you could use both together. In my experience, xml-object.r is all I need to parse XML ..... the XML I encounter just does not need the extra oomph supplied by parse-xml.r

28-Jun-09 7:49
793Grahamthat's the complementary script ...28-Jun-09 7:42
792SunandaDon't remember if I tried parse-xml. I do use xml-object wich works well for me: http://www.rebol.org/view-script.r?script=xml-object.r28-Jun-09 7:33
791Grahamhas anyone got a working copy of parse-xml.r from the library?28-Jun-09 7:26
790GeomolIn case, it's needed, RebXML spec: http://www.fys.ku.dk/~niclasen/rebxml/rebxml-spec.html24-Jun-09 21:13
789BrianHindermediate -> intermediate24-Jun-09 14:07
788BrianHThat's because the "intermediate" contexts don't really indermediate - they get applied in order by DO.24-Jun-09 14:06
787BrianHFunctions can be serialized, but the only word contexts that get restored are the global and thee function local context. Any intermediate contexts, like object contexts, don't get restored.24-Jun-09 14:03
786Sunanda[we're off topic for XML -- please continue in Library if you want more details]. Stored in text files and binary files (which are generally just compressed text files. No database!24-Jun-09 9:00
785GrahamI'm pretty sure rebol.org doesn't use a db backend.24-Jun-09 8:43
784Grahamand these are stored where? In the filing system?24-Jun-09 8:42
783GrahamInteresting...24-Jun-09 8:41
782SunandaWe have similar issues at REBOL.org where just about everything [scripts, Ml posts, internal data structures, etc] is objects, or blocks of objects. Data sanitisation and object upgrading is a major part of the gig.24-Jun-09 8:30
781GrahamAnd when my app crashes as it does often enough, I save state as an object .. and that has to be checked as well when reloaded.24-Jun-09 8:19
780GrahamI have configs that are saved in the db as objects ... and those i have to check each time :(24-Jun-09 8:19
779SunandaThat makes life a bit simpler.....Objects with year-long lifespans can be harder to manage :)24-Jun-09 8:14
778Grahamand then I can discard it ...24-Jun-09 8:13
777GrahamWhat I need to do is to create the object, create the xml from the object, and then submit it via ssl to the gateway server24-Jun-09 8:13
776GrahamI'll just change the object templates24-Jun-09 8:12
775SunandaYou may have some other issues to consider as part of building/loading the data structures. For example, Version2 of the application adds some fields not present in V1. To avoid a one-off bulk conversion exercise, the load process needs to check each object and add missing fields with default values.24-Jun-09 8:09
774Maximok.24-Jun-09 8:06
773GrahamI'll be creating an empty object and then populating it once created24-Jun-09 8:04
772Maximif the db returns lists of varying length and types... you're better off creating a structured approach to a recursive initialisation.24-Jun-09 8:03
771Maximwell if the pharmacy object can have 1 or 5 addresses, some people 3 different ways to refer to patients, etc... then the copy still has to be meddled with.24-Jun-09 8:02
770Grahamwhat do you nean by structure has to remain pretty static?24-Jun-09 8:01
769Grahamdeep copy24-Jun-09 8:00
768Maximtalking to who?24-Jun-09 8:00
767Grahamwhat do you mean?24-Jun-09 8:00
766Maximbut note that your object's structure has to remain pretty static for any type of deep copy like this to be usefull.24-Jun-09 8:00
765SunandaDo has some dangers if you do not trust the code involved. This works for me, and keeps the load/all (but not the self).....Even more tortured: a: first reduce load/all mold pharmacy24-Jun-09 7:59
764Maximnot really, the way I see it is that we are taking advantage of rebol's features.24-Jun-09 7:59
763GrahamThis solution seems a little tortued :)24-Jun-09 7:57
762Maximyes since I removed the make.24-Jun-09 7:55
761Grahama: do mold pharmacy ;24-Jun-09 7:55
760Maxima: do mold pharmacy [ ]24-Jun-09 7:53
759Grahamso, I have to now do

a: do load mold make pharmacy [ ] ?

24-Jun-09 7:52
758SunandaIt worked for me, when i tried it.24-Jun-09 7:51
757Maximok, to use do, you must forget the /all.

so the above, minus the /all should work with self... (it does in my tests)

24-Jun-09 7:50
756Grahambecause it won't work?24-Jun-09 7:49
755Maximseems functions can be serialized, but I don't understand why the self isn't being bound to the object..that is strange.24-Jun-09 7:49
754SunandaWhy not remove the self ? [not a metaphysical question in this context] ph: make object! [ name: none init: func [n][ name: n ] ]24-Jun-09 7:47
753Maximfunctions cannot be serialized... so they have to be bound somehow.24-Jun-09 7:45
752Maximif you have a function inside, I think you have to do it instead of load it.24-Jun-09 7:45
751Grahamseems not :(

>> pharmacy: make object! [ [ name: none [ init: func [ n ][ [ self/name: n [ ] [ ] >> a: load mold/all make pharmacy [] >> probe a make object! [ name: none init: func [n][ self/name: n ] ] >> a/init "testing" ** Script Error: self has no value ** Where: init ** Near: self/name: n

24-Jun-09 7:43
750Grahamahh ... well problem solved :)24-Jun-09 7:13
749Maximyes.24-Jun-09 7:13
748Grahamie. I load a serialized form of the object24-Jun-09 7:12
747GrahamSo, I can continue to make the objects as I have been doing. But just before I use it ... I load mold/all on it to ensure I have unique objects24-Jun-09 7:12
746Maximbut remember to use mold/ALL cause otherwise you end up with gibberish...24-Jun-09 7:11
745Maximex:

load mold/all make object! [ a: make object! [ b: make object! [ c: "tadam!" ] ] ]

will effectively create a complete duplicate of the whole object tree.

24-Jun-09 7:10
744GrahamI was just thinking that.24-Jun-09 7:10
743Maximyou can just do a mold/all load, that will in effect copy the whole tree along with all the series too.24-Jun-09 7:09
742GrahamLet me understand this .. if I have an object that needs other objects more than 1 deep .. I can't use that to clone other objects without creating references instead of copies.24-Jun-09 7:08
741Maximthe downside is that access either needs a wrapper func, or is done via indexes...

actually attributes could be an object, since their names are mutually exclusive within an element.

24-Jun-09 7:06
740Maximwhat I can suggest is that you build your objects like so:

xml-attribute: context [ name: "someattr" value: "somevalue" ]

xml-tag: context [ name: "FileID" content: [] ; a block of inner xml-tag objects attributes: [] ; a block of xml-attribute names ]

then all you do is nest objects in objects, filling them up item by item recursively using DB data.

24-Jun-09 7:04
739Grahamthis is part of the xsd .. found an example http://stackoverflow.com/questions/790118/jaxb-types-problem24-Jun-09 6:47
738Grahamit's all in a DB.24-Jun-09 6:45
737Grahamwell, output is first, reading is the next task :)24-Jun-09 6:45
736Maximwhat is the source of data?24-Jun-09 6:45
735MaximMUCH easier than loading it.24-Jun-09 6:44
734Maximyou only need to output xml? then that is very easy.24-Jun-09 6:44
733GrahamMaybe I need to use the factory way ..24-Jun-09 6:44
732GrahamI'm creating the XML from scratch .. and not reading it in.24-Jun-09 6:43
731Maximmy client has a few thousand data types to cope with ;-) rebxml allows you to load that up pretty quickly...but not using the xsd obviously.

its parser builds up a string and then loads it. I found it to be quite fast actually. its MUCH faster than firefox, for example.

24-Jun-09 6:42
730GrahamThe XSD I'm looking at has about 30-40 complex data types24-Jun-09 6:40
729GrahamA hack.24-Jun-09 6:39
728Maxim;-)24-Jun-09 6:38
727Maxim>> probe load replace {#[object! [a: #[object! [b: #[object! [c: "%VALUE%"]]]]]]} "%VALUE%" "tadam!" make object! [ a: make object! [ b: make object! [ c: "tadam!" ] ] ]24-Jun-09 6:38
726Maximsomething like...24-Jun-09 6:36
725Maximcause with rebol its easy to hack stuff up using out of the box tricks.....24-Jun-09 6:36
724Grahamstatic largely24-Jun-09 6:35
723Maximdoes the xml structure change a lot (lists of data, alternative or optional elements, etc) or is it really static?24-Jun-09 6:34
722Maximin the later, you can add code in the addressobj which will be executed everytime you create an object using it.

for example: addressobj: [ number: 666 street: "styx lane" city: "pandemonium" address: rejoin [number " " street " " city] ]

24-Jun-09 6:33
721GrahamI'm having to create nested objects 7 levels deep ...24-Jun-09 6:32
720Maximso graham... instead of doing:

; note this is an object, context is a shortcut for make object! , like func is a shortcut for make function! addressobj: context [ number: 666 street: "styx lane" city: "pandemonium" ] pharmacy: context [ address: make addressobj [ ] ]

you do:

; note this is a block addressobj: [ number: 666 street: "styx lane" city: "pandemonium" ]

pharmacy: context [ address: context addressobj ]

24-Jun-09 6:30
719BrianHThe spec block is like an init function that goes away after it runs, without needing to assign none to any fields.24-Jun-09 6:25
718Maximthat is how its done in GLayout to assign the same setup to many styles.24-Jun-09 6:25
717Maximthats another ways of doing it... instead of storing reference objects you store reference spec blocks.24-Jun-09 6:25
716BrianHCode in the spec block doesn't get attached to the object.24-Jun-09 6:24
715Grahamhuh?24-Jun-09 6:23
714SunandaOne way to do init is as open code in the object....That only "inits" the original object, not anything MAKEd from it. But it may be useful in some cirumstances, and it does not become part of the object: o: make object! compose [print "init" (a: 99) a: 1 b: 2]24-Jun-09 6:21
713GrahamUsing your method of creating a special context is going to screw up my obj2xml function :(24-Jun-09 6:19
712Grahami wouldn't have 100s of init functions anymore .. :)24-Jun-09 6:17
711Maximnot much would really be gained, but it migh trigger some GC cleanup.24-Jun-09 6:17
710GrahamI guess I can set the init functions to none after they've done their jobs ?24-Jun-09 6:16
709MaximI usually creat myself a new function which calls make and the object init (wether class or prototype based) if that init needs to create new inner objects, then its responsible for doing so.

in your case the make-xml-object could accept an xml string and then call make-xml-object recursively for each element it finds.

24-Jun-09 6:15
708BrianHOOP in a prototype-based language with function values instead of methods is different. Classes are emulated if need be, but don't always need to be. In REBOL even delegation is explicit, unlike most other prototype-based object languages.

For the best maintenance use factory functions that create objects based on standard specs. Beyond that, different models are better for different tasks. Sometimes you assign function values to fields, sometimes you use class objects, sometimes class names that are looked up at runtime.

24-Jun-09 5:40
707GrahamIn terms of maintenance?24-Jun-09 5:35
706Grahamwhich is the more robust method?24-Jun-09 5:34
705BrianHIf you like. The standard way of doing things in REBOL is to have functions that create objects, rather than constructor methods.24-Jun-09 5:33
704GrahamAs you can see, I've never played with rebol objects before ...24-Jun-09 5:32
703GrahamIf that is the case, perhaps I need a 'create function with each object, and at init time, iterate thru all the objects calling their create function ?24-Jun-09 5:30
702Grahamso , instead of

a: make pharmacy []

I have to

a: make pharmacy [ address: make addressobj []]

24-Jun-09 5:27
701BrianHEvery MAKE object! takes a spec block that is an init function, in effect.24-Jun-09 5:25
700BrianHWith explicit construction in the spec block, like this: a: make proto [ b: make inner-proto [...] ]24-Jun-09 5:24
699GrahamCreate them using the init function ??24-Jun-09 5:24
698GrahamSo, how does one create nested unique objects?24-Jun-09 5:22
697GrahamOuch24-Jun-09 5:22
696BrianHYeah.24-Jun-09 5:21
695Grahamso if I have

pharmacy: make object! [ address: make addressobj [ ] ]

and the address object has objects in it ... they will be shared??

24-Jun-09 5:21
694BrianHBut then the class functions are accessed through obj/class/method obj, insstead of obj/method.24-Jun-09 5:19
693Grahamis it objects within objects within objects?24-Jun-09 5:18
692GrahamOh ....24-Jun-09 5:17
691MaximR2 shares objects within objects. the class is not re-created at each make [].24-Jun-09 5:15
690Maximbut its a large object. still using the class system, I can allocate 1000000 nodes using about 400MB. with instances, 10000 obects take much more than that.24-Jun-09 5:14
689Grahamunclear as to why yours is shared and mine isn't24-Jun-09 5:14
688Grahamwell, I doubt that I would have more than a few hundred objects... but ...24-Jun-09 5:14
687Maximwith liquid the difference is staggering when over 10000 objects.24-Jun-09 5:13
686Maximmy example above, will share the init function amongst all the 2000 objects... and its going to be faster since no binding occurs... well only the CLASS word is bound but its content is the same in all instances.24-Jun-09 5:11
685Grahamwhat's the diff between yours and mine?24-Jun-09 5:11
684Maximit is bound each time, so if you have 2000 instances, you actually have 2000 times that function in ram, it adds up quickly for larger objects... for such a simple object, it might not be all that bad...24-Jun-09 5:10
683GrahamPerhaps I'm not clear on this .... If I create a pharmacy object like this

pharmacy: make object! [ name: none init: func [ n ][ self/name: n ] ]

is the init function shared by all the subsequent pharmacy instances?

24-Jun-09 4:56
682GrahamThat's what i was going to do initially, but I thought it would be easier to maintain if I kept the init methods inside the objects24-Jun-09 4:47
681Maximclass is shared amongst all my-tag instances, and is never bound to any of them, so its both very fast and very RAM efficient.. exponentially so with large classes.24-Jun-09 3:59
680Maximthe init is a context with one function, to which you supply the outer (instance) which holds the data:

my-tag: context [ data: "tototo" attribute-1: "red" class: context [ init: func [instance][ instance/data: copy "" instance/attribute-1: copy "blue" ] ] ]

to init the an instance of my-tag:

new-tag: make my-tag [class/init self]

24-Jun-09 3:58
679BrianHClass-based objects are emulated in REBOL.24-Jun-09 3:56
678Maximyes, the best method is to have some form of dtd or schema, and use class-based objects.24-Jun-09 3:55
677BrianHNot a good idea for data objects, which could number in the thousands, each with their own bound copy of the functions.24-Jun-09 3:54
676GrahamUsing objects means i can store the functions that initialize it inside the object.24-Jun-09 3:52
675Grahamthat's why I said "if" ...23-Jun-09 23:37
674Grahamat this time .. it may come back to you23-Jun-09 23:37
673Maximread above, I don't ;-)23-Jun-09 23:35
672Grahamas should i.23-Jun-09 23:35
671GrahamYou should add a comment to the discussion page if you remember.23-Jun-09 23:35
670MaximI remeber it also tripping on some of the XML files I gave it... don't remember the problems... but its error handling /recovery was very shaky IIRC.23-Jun-09 23:34
669GrahamI suspect the author is no longer reboling23-Jun-09 23:31
668Grahameven if the full path is specified.23-Jun-09 23:30
667Grahamit accepts the first one it finds23-Jun-09 23:30
666Grahamrebelxml gets confused if there is more than one path with the same name23-Jun-09 23:29
665Maximbut the rebxml tools (on rebol.org) as-is are very usefull, so some utf-8 support and are less buggy than rebelXML in my previous tests.23-Jun-09 23:26
664GrahamOk, so we have established that everyone does it their own way :)23-Jun-09 23:24
663Maximanyhow... the xml tools I currently have are not yet tested enough to be release ready.23-Jun-09 23:11
662Maximmy newer version doesn't have the schema validation process.... that is a very complex engine to build. schemas and Parse traversal do not follow the same algorythm... so its a bitch to implement.23-Jun-09 23:10
661BrianHAnd mine is lost :(23-Jun-09 23:10
660Maximbut all of that is not open source.23-Jun-09 23:09
659Maximoops.. embedded text I mean.23-Jun-09 23:09
658Maximmy engine does support embedded types, but ignored it by default... it was also byte reversible... a loaded xml block loaded through the engine was saved back exactly, byte for byte, checksum proofed.23-Jun-09 23:08
657BrianHI was parsing xhtml and other XML of the like. Subelements of mixed types in order with text between them than mattered.23-Jun-09 23:07
656Maximmy paths.. namespace works... for sure. did you know you can have colon in word names in R2 ! but i didn;t use that, I just used tags directly. more obvious than strings, and the exact same effort and speed.23-Jun-09 23:06
655BrianHYour paths can't access multiple subelements of the same type, or embedded text. It might have worked for that customer but not the general case. No namespace support either.23-Jun-09 23:05
654Maxima later version, using schema validation, understands multiple subelements and automatically converts them to blocks IIRC.

so you do document/element/3/subelement/#attribute.

23-Jun-09 23:05
653GrahamLooks like we need an article on best practices here ...23-Jun-09 23:04
652MaximI wanted direct access to all elements within rebol.23-Jun-09 23:03
651BrianHI wrote a simple xpath compiler too (but don't know where it is now).23-Jun-09 23:03
650BrianHXML *is* case-sensitive. Your paths can't access multiple subelements of the same type, or embedded text.23-Jun-09 23:02
649Grahamby position!23-Jun-09 23:02
648Maximbut brian, how do you acess it?23-Jun-09 23:01
647GrahamXML can be case sensitive??23-Jun-09 23:01
646Maximhahaha23-Jun-09 23:00
645Maximits just that in my tests, either you can create, read or set some of the datatypes via path notation. so only string based types allow full XML qualification.23-Jun-09 23:00
644BrianHMy positional version handles multiple subelements of the same type, and using strings rather than words lets you use tags that don't match word syntax or are case=sensitive.23-Jun-09 23:00
643Maximnote that in the above, you can replace types within so it could be words instead of tags.23-Jun-09 22:58
642GrahamUsing tags looks ugly :)23-Jun-09 22:58
641BrianHReally? I went positional: ["element" "namespace" ["attribute" "value"] ["subelement" ...] "text" ...] with missing namespace or attribute block being #[none], so defaults can be done with ANY.23-Jun-09 22:57
640MaximI've never posted that specific version cause it was closed source for a client. but I have my own new engine, which does the same, but attacking the parse rules directly... its probably faster. I've not released it.23-Jun-09 22:57
639GrahamI guess the duplicate elements could be solved by using blocks for them23-Jun-09 22:57
638GrahamI find working with objects much easier though ...23-Jun-09 22:56
637MaximAnd you can access it this way:

document/<element>/<subelement>/#attribute document/<element>/<subelement>/.

23-Jun-09 22:55
636Maximthe . is assigned the value of the elements.

the above would result from the following XML: <element> <subelement attribute="attr-value"> subelement content </subelement> </element>

23-Jun-09 22:54
635Maximthe most stable engine I built which accepted all xml possibilities ended loading xml like so:

[ <element> [<subelement> [#attribute "attr-value" . "subelement content"]]]

23-Jun-09 22:52
634GrahamHave you posted your modifications anywhere??23-Jun-09 22:52
633GrahamOr name spaces23-Jun-09 22:51
632GrahamAlthough the XML I'm dealing with doesn't have duplicate elements.23-Jun-09 22:51
631Maximand you can easily separate attributes from elements, just by affecting them to different types.23-Jun-09 22:50
630GrahamTrue23-Jun-09 22:50
629Maximcause you have have the same element severall times, which is valid xml, but invalid in contexts.23-Jun-09 22:50
628Maximyes all the time. accessing is exactly the same as for objects. its actually much more flexible.23-Jun-09 22:49
627GrahamSo, you used blocks instead of objects?23-Jun-09 22:48
626Maxim(...objects instead of blocks ....)23-Jun-09 22:46
625Maximbuilding output objects instead would be simple, but the RAM/Speed/symbol table implications of all the binding involved makes this un-optimal.23-Jun-09 22:46
624MaximI also replaced the use of url for the tag words because they fail when using namespaced xml elements.23-Jun-09 22:44
623Maxima modified version of John's rebXML tools. changed the output structure to allow rebol's path notation to be used to traverse the loaded xml.23-Jun-09 22:42
622GrahamWhat are people using to construct large XML documents ... of 100s of lines?23-Jun-09 22:41
621GrahamI was using rebelxml to construct xml ... but I came across some bugs. So this way of doing it looks easier ....23-Jun-09 1:44
620Grahamremove the newlines to solve that issue :)23-Jun-09 0:02
619Grahamformat-xml: func [ xml /local out space prev ][ out: copy "" spacer: copy "" prev: copy </tag> foreach tag load/markup xml [ either tag = find tag "/" [ ; we have a close tag ; reduce the spacer by a tab unless the previous was an open tag either not tag? prev [ ; not a tag remove/part spacer 4 ][ ; is a tag if prev = find prev "/" [ ; last was a closing tag remove/part spacer 4 ] ] ][ either tag? tag [ ; current is tag ; indent only if the prev is not a closing tag if not prev = find prev "/" [ insert/dup spacer " " 4 ] ][ ; is data insert/dup spacer " " 4 ] ] repend out rejoin [ spacer tag newline ] prev: copy tag ] view layout compose [ area (out) 400x400 ] ]

obj2xml: func [ obj [object!] out [string!] /local o ][ foreach element next first obj [ repend out [ to-tag element ] either object? o: get in obj element [ obj2xml o out ][ repend out any [ o copy "" ] ] repend out [ to-tag join "/" element ] ] ]

23-Jun-09 0:02
618Steevethen, for NONE! values, it will add an empty line22-Jun-09 23:59
617Grahamprobably should change line repend out [ o newline ] to repend out [ any [ o copy "" ] newline ]22-Jun-09 23:57
616GrahamYes, separate script does the tabulations22-Jun-09 23:52
615SteeveHmm.. Really, have you the tabulations ?22-Jun-09 23:51
614Grahamgives this

<a> testing </a> <b> again </b> <c> <d> testing2 </d> <e> again2 </e> <f> <g> testing3 </g> <h> again3 </h> </f> </c> <i> finished </i>

22-Jun-09 23:49
613Graham>> probe obj make object! [ a: "testing" b: "again" c: make object! [ d: "testing2" e: "again2" f: make object! [ g: "testing3" h: "again3" ] ] i: "finished" ]22-Jun-09 23:48
612Grahamcrap ... clipboard bug22-Jun-09 23:48
611Grahamusing this

obj2xml: func [ obj [object!] out [string!] /local o ][ foreach element next first obj [ repend out [ to-tag element newline ] either object? o: get in obj element [ obj2xml o out ][ repend out [ o newline ] ] repend out [ to-tag join "/" element newline ] ] ]

22-Jun-09 23:47
610GrahamThis seems to work for me ...

obj2xml: func [ obj [object!] out [string!] /local o ][ foreach element next first obj [ repend out [ to-tag element newline ] either object? o: get in obj element [ obj2xml o out ][ repend out [ o newline ] ] repend out [ to-tag join "/" element newline ] ] ]

22-Jun-09 23:42
609GreggThere must be something, but I don't have anything here that turned up, and I don't remember doing one myself. If it helps, you could use the JSON converter in %json.r as a starting point.22-Jun-09 22:00
608GrahamNow has anyone written a recursive routine to turn a rebol object into XML? I couldn't find anything like this on rebol.org yet it doesn't sound hard to do ...22-Jun-09 13:49
607GrahamNo matter .. it was easy enough.22-Jun-09 13:49
606Graham/indent .. not index22-Jun-09 10:52
605GrahamHas anyone written anything to format/index XML documents?22-Jun-09 10:52
604GeomolRebXML spec: http://www.fys.ku.dk/~niclasen/rebxml/rebxml-spec.html Scripts are in the Library: http://www.rebol.org2-Mar-09 16:12
603ChrisOk, another revision. This has a few more methods, I may strip them down to read-only, as I don't need to manipulate the object though I left them in for completeness.

>> do http://www.ross-gill.com/r/qdom.r connecting to: www.ross-gill.com Script: "QuickDOM" (none) >> doc: load-dom {<some><xml id="foo">to try</xml></some>} >> foo: doc/get-by-id "foo" >> foo/name == <xml> >> foo/value == [ /id "foo" # "to try" ] >> kids: foo/children == [make object! [ name: # value: "to try" tree: [ # "to try" ] position: [ ... >> kids/1/value == "to try" >> doc/tree/<some>/<xml>/(#) == "to try"

4-Dec-08 15:11
602ChrisThis is not an exercise in bloat, I plan to implement only a few key methods. Though if anyone has any requests?3-Dec-08 13:40
601Chris; You can still parse the tree too: parse doc/tree [<some> into [<xml> "to try"]]3-Dec-08 13:36
600Chrisdo http://www.ross-gill.com/r/qdom.r

doc: load-dom {<some><xml>to try</xml></some>} values: doc/get-by-tagname <xml> values/1/value = "to try"

3-Dec-08 13:35
599ChrisOnly one method at the moment - get-by-tagname

Note, this is not an attempt to implement W3 DOM. Just a quick approximation for fast manipulation (hence the name). It's object happy, not sure of the weight considerations as such.

3-Dec-08 13:33
598Chris; Next, Quick DOM:

do http://www.ross-gill.com/r/qdom.r

3-Dec-08 13:31
597ChrisSo ymmv depending on need.3-Dec-08 13:30
596ChrisNote, this parser is destructive - ie. flattening will only provide an approximation of the original xml string.3-Dec-08 13:29
595ChrisAll the 'into values are a bit of a pain, but work can be broken up...3-Dec-08 5:38
594Chrisresponse: context [ status: name: value: none ]

example: {<rsp> <status>Good</status> <payload> <value name="one">two</value> </payload> </rsp>}

probe make response [ parse load-xml example [ <rsp> into [ <status> set status ["Good" | "Bad"] <payload> into [ <value> into [ /name set name string! # set value string! ] ] ] ] ]

3-Dec-08 5:36
593Chris>> load-xml "<try>This</try>" == [ <try> "This" ]3-Dec-08 5:31
592ChrisAlso, a tag with no attributes containing only text will only contain text:3-Dec-08 5:30
591ChrisI thought about the # convention. # can be used in parse literally. It may have no semantic meaning, but is a very concise anchor.3-Dec-08 5:29
590ChrisHmm, missing bracket.3-Dec-08 5:27
589Chris>> load-xml {<some xml="to">Try</some>} == [ <some> /xml "to" # "Try" ] ]3-Dec-08 5:26
588ChrisWhere 'thing is <tag> /attribute or # for text. And value is [container] "text" or none3-Dec-08 5:24
587ChrisMore consistent, I feel. The result is now of the format: some [thing value]3-Dec-08 5:24
586ChrisI've changed this a little. More or less parseable.3-Dec-08 5:22
585ChrisSorry!20-Nov-08 0:56
584ChrisSorry, [tag! any [refinement! [string! | none!]] [string! | none! | some block!]]20-Nov-08 0:56
583GreggCool.20-Nov-08 0:53
582ChrisA tag block will always be [tag! any [refinement! [string! | none!]] [string! | none! | block!]]20-Nov-08 0:49
581ChrisSorry, forgot I'd assigned pop: :take -- try again.20-Nov-08 0:48
580Gregg** Script Error: pop has no value ** Where: load-xml ** Near: mk: insert mk: back mk20-Nov-08 0:47
579Chris; Usage:

do http://www.ross-gill.com/r/qxml.r load-xml {<some xml="to">Try</some>}

20-Nov-08 0:45
578ChrisThis is a quickie -- designed to make 'parse-xml output more parseable:

http://www.ross-gill.com/r/qxml.r

Any thoughts, comments?

20-Nov-08 0:44
577Steeveor worst, as u want11-Nov-08 22:25
576Steeveoh i have a better bad puns: GUI-lty11-Nov-08 22:25
575Steeveoh you're here...11-Nov-08 22:16
574Steeve*still11-Nov-08 22:15
573Steeveis Henrik steel working on revamping ?11-Nov-08 22:14
572Steevethe first time i saw his new styles, i had some glue in my eyes11-Nov-08 22:12
571Henrikit's at times like that, that REBOL deserves advertising with a live demo.11-Nov-08 22:12
570Geomol:)11-Nov-08 22:08
569SteeveIt's also a refernce to the "special" talent of Carl in terms of mixing colors ;-)11-Nov-08 22:07
568GeomolREBOL is GLUE! What about calling the new GUI something related to glue? Or just "GLUE".11-Nov-08 21:59

Return to Index Page