Hi all,
I am learning the DOM API and reading through the UniVerse BASIC Extension
Guide and some PDFS on PickWiki and U2UG, I have been able to piece together
some partially working example code. What I am having trouble understanding
is the correct way to navigate the DOM for MV Elements. My example below is
a simple blog that uses MV to store the posts. I can write the BLOG.TITLE
element, however I am getting confused trying to write the POST.DATE,etc. I
would greatly appreciate your insight as to what I am missing. Thanks, Norm
blog.xml: used as the IN file for the DOM
<?xml version="1.0" encoding="UTF-8"?>
<ROOT>
<BLOG>
<_ID></_ID>
<BLOG.TITLE/>
<POST.DATE_MV>
<POST.DATE></POST.DATE>
</POST.DATE_MV>
<POST.TITLE_MV>
<POST.TITLE></POST.TITLE>
</POST.TITLE_MV>
<POST.ENTRY_MV>
<POST.ENTRY></POST.ENTRY>
</POST.ENTRY_MV>
</BLOG>
</ROOT>
UniBASIC code:
PROGRAM XMLOUT
$OPTIONS INFORMATION
$INCLUDE UNIVERSE.INCLUDE XML.H
PRECISION 9
CLR=@(-1) ;* code to use for clearing the screen
OPEN "","BLOG" TO BLOG ELSE
STOP "CAN'T OPEN BLOG"
END
OPEN "DICT", "BLOG" TO BLOG.DICT ELSE
STOP "Can't open BLOG dictionary"
END
PRINT CLR:
PRINT "ENTER BLOG NAME"
PRINT
PRINT "BLOG NAME":
INPUT INPT
IF INPT EQ '' OR INPT EQ 'END' OR INPT EQ 'QUIT' THEN
RETURN
END ELSE
READ BLOG.REC FROM BLOG,INPT THEN
NAME = INPT
DATE = BLOG.REC<2>
TITLE = BLOG.REC<3>
ENTRY = BLOG.REC<4>
DOC = "BLOG.xml"
STAT = ""
STAT.ERROR = 0
ROOT = "/ROOT/BLOG"
ID_NODE = '/_ID'
OUT = 'blog-out.xml'
PRINT NAME
STAT = XDOMOpen(DOC,XML.FROM.FILE, BLOG_DOM)
GOSUB STAT.ERROR
STAT = XDOMLocate(BLOG_DOM, ROOT:ID_NODE,'', blognode)
GOSUB STAT.ERROR
STAT = XDOMCreateNode(blognode,'',NAME,XDOM.TEXT.NODE, blogtext)
GOSUB STAT.ERROR
STAT = XDOMAddChild(blognode,'/':ROOT:ID_NODE,'',blogtext,
XDOM.NODUP)
GOSUB STAT.ERROR
PRINT ID_NODE:STAT
STAT =
XDOMLocate(BLOG_DOM,ROOT:ID_NODE:'/POST.DATE_MV/POST.DATE','',pd_node)
GOSUB STAT.ERROR
PRINT 'POST.DATE LOCATE ':STAT ;* used for trouble shooting
STAT = XDOMCreateNode(pd_node,'',DATE,XDOM.TEXT.NODE,pd_text)
GOSUB STAT.ERROR
PRINT 'POST.DATE CREATE NODE ':STAT ;* used for trouble
shooting
STAT = XDOMAddChild(pd_node,'/POST.DATE','',pd_text,XDOM.NODUP)
GOSUB STAT.ERROR
PRINT 'POST.DATE ADD CHILD ':STAT ;* used for trouble shooting
PRINT "New text ":ID_NODE:" status =":STAT ;* used for trouble
shooting
STAT = XDOMWrite(BLOG_DOM,OUT,XML.TO.FILE)
GOSUB STAT.ERROR
PRINT 'writing to file = ':STAT
PRINT 'wrote: ':OUT:' to file.'
END ELSE
PRINT "CANT READ THE SO RECORD"
RETURN
END
STAT.ERROR:
IF STAT.ERROR <> XML.SUCCESS THEN
STAT = XMLGetError(errCode,errMsg)
PRINT errCode:' ':errMsg
STOP
END
RETURN
END
END
_______________________________________________
U2-Users mailing list
[email protected]
http://listserver.u2ug.org/mailman/listinfo/u2-users