r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[XML] xml related conversations

Graham
24-Jun-2009
[777x2]
What I need to do is to create the object, create the xml from the 
object, and then submit it via ssl to the gateway server
and then I can discard it ...
Sunanda
24-Jun-2009
[779]
That makes life a bit simpler.....Objects with year-long lifespans 
can be harder to manage :)
Graham
24-Jun-2009
[780x2]
I have configs that are saved in the db as objects ... and those 
i have to check each time :(
And 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.
Sunanda
24-Jun-2009
[782]
We 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.
Graham
24-Jun-2009
[783x3]
Interesting...
and these are stored where? In the filing system?
I'm pretty sure rebol.org doesn't use a db backend.
Sunanda
24-Jun-2009
[786]
[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!
BrianH
24-Jun-2009
[787x3]
Functions 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.
That's because the "intermediate" contexts don't really indermediate 
- they get applied in order by DO.
indermediate -> intermediate
Geomol
24-Jun-2009
[790]
In case, it's needed, RebXML spec:
http://www.fys.ku.dk/~niclasen/rebxml/rebxml-spec.html
Graham
28-Jun-2009
[791]
has anyone got a working copy of parse-xml.r from the library?
Sunanda
28-Jun-2009
[792]
Don'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.r
Graham
28-Jun-2009
[793]
that's the complementary script ...
Sunanda
28-Jun-2009
[794]
Both 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
Graham
28-Jun-2009
[795x2]
Got a working example of their use?
I keep getting errors
Sunanda
28-Jun-2009
[797]
This 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
Graham
28-Jun-2009
[798x5]
Hmm.  There is no 'xml-object function
oh ...sorry
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?