How does revAppendXML work?

Sarah Reichelt sarah.reichelt at gmail.com
Thu May 25 21:58:13 EDT 2006


> I have multiple xml files that are identical in format...
>
> <?xml version="1.0"?>
> <StudentURL_table>
>   <URL IDnum="1">
>     <subject> Art</subject>
>     <key_words> Fine Art</key_words>
>     <Grade> 5</Grade>
>
> ...
>
> They just have different <URL IDnum #> content. Such as...
>
>  <URL IDnum="1">
>     <subject> Art</subject>
>     <key_words> Fine Art</key_words>
>     <Grade> 5</Grade>
>     <Standard> Creativity</Standard>
>     <Title> SPARK Site</Title>
>     <Description> This site is great for introducing students to the varied definitions of fine art and expression.</Description>
>     <Submitted_by> John Art</Submitted_by>
>     <emailAddress> art at mail.com</emailAddress>
>     <school> Orchard School</school>
>     <WebAddress> www.kqed.org/spark</WebAddress>
>   </URL>
>   <URL IDnum="2">
>     <subject> Art</subject>
>     <key_words> San Fracicso, Museum of Modern Art</key_words>
>     <Grade> 5</Grade>
>     <Standard> VAPA</Standard>
>
> ...
>
> I want to take these multiple XML files and combine them into one large xml file with the same format.
>
> I was thinking I could do something like this:
>
>  answer folder "Select XML folder" as sheet
>   if it = "" then exit mouseUp
>   set the defaultFolder to it
>
>
>   put the files  into tFiles
>   put the number of lines of tFiles into tNumberofXMLFiles
>   put line 1 of tFiles into theFileName
>   put URL ("file:" & theFileName) into tData
>
> get revCreateXMLTree(tData,true,true,true)
>
> put the result into targetXMLFile
>
>
> put 1 into x
> repeat tNumberOfXMLFiles
>
>
>   revAppendXML targetXMLFile,"/StudentURL_table/",URL "file:" & line x of tFiles
>   add 1 to x
>   end repeat
> --
> Put revXMLText(targetXMLFile,,true)
>
> end mouseUp
>
> -----------------------------------------------
>
> However, I appear to be misunderstanding what revAppendXML does, or how to use it correctly.


I can't see any major problem with what you are doing, except possibly
for the specification of the parentNode for the revAppendXML command.
Try leaving out the /'s.

I would also recommend doing it in 2 stages: read the file into a
variable, then append the variable. e.g.

  put URL ("file:" & line x of tFiles) into tXMLdata
  revAppendXML targetXMLFile, "StudentURL_table", tXMLdata

I always surround the file stuff with brackets before using put or get
URL. It seems to be more reliable.

And after each XML command or function, check the result and see if it
contains "xmlerr".

HTH,
Sarah



More information about the Use-livecode mailing list