I do not have the manual with me at the moment, but you need to go down one 
more level. The text is in the text node under "name"

-Rick

On Oct 4, 2011, at 3:09 PM, "Jason Lin" <temp...@ucla.edu> wrote:

> Hi.
> 
> I tried to use the XDOM API (XML for BASIC API Programmatic
> Interfaces) in Universe Basic for parsing XML file and extracting
> element values but for some reason I got error when calling the  
> XDOMGetNodeValue function.
> 
> 
> Here is an example.
> Suppose I have a simple XML file called "TEST.xml" stored in a type 19
> file (directory) called TEST.FILE:
> 
> LIST.ITEM TEST.FILE TEST.xml 01:25:41pm  04 Oct 2011  PAGE    1
> 
>    TEST.xml
> 001 <?xml version="1.0"?>
> 002 <test>
> 003     <name>John Smith</name>
> 004     <id>12345</id>
> 005 </test>
> 
> 
> I also created following program which uses XDOM API and a XPath
> string to locate the "name" element node in TEST.xml and extract its
> value.
> 
>> ED TEST.BP TEST.XDOM
> 50 lines long.
> 
> ----: P999
> 0001: $OPTIONS DEFAULT
> 0002: $INCLUDE UNIVERSE.INCLUDE XML.H
> 0003: !
> 0004:       STATUS = XDOMOpen("TEST.FILE/TEST.xml", XML.FROM.FILE,
> XDOMHandle)
> 0005:       BEGIN CASE
> 0006:          CASE STATUS = XML.SUCCESS
> 0007:             CRT "XDOMOpen Success"
> 0008:          CASE STATUS = XML.ERROR
> 0009:             CRT "XDOMOpen Error"
> 0010:             GOSUB DISPLAY.XML.ERROR ; STOP
> 0011:          CASE STATUS = XML.INVALID.HANDLE
> 0012:             CRT "XDOMOpen Invalid Handle"
> 0013:             GOSUB DISPLAY.XML.ERROR ; STOP
> 0014:       END CASE
> 0015: !
> 0016:       XPath = '/test/name'
> 0017:       nsMap = ''
> 0018:       STATUS = XDOMLocate(XDOMHandle, XPath, nsMap, nodeHandle)
> 0019:       BEGIN CASE
> 0020:          CASE STATUS = XML.SUCCESS
> 0021:             CRT "XDOMLocate Success"
> 0022:          CASE STATUS = XML.ERROR
> 0023:             CRT "XDOMLocate Error"
> 0024:             GOSUB DISPLAY.XML.ERROR ; STOP
> 0025:          CASE STATUS = XML.INVALID.HANDLE
> 0026:             CRT "XDOMLocate Invalid Handle"
> 0027:             GOSUB DISPLAY.XML.ERROR ; STOP
> 0028:       END CASE
> 0029: !
> 0030:       STATUS = XDOMGetNodeValue(nodeHandle, nodeValue)
> 0031:       BEGIN CASE
> 0032:          CASE STATUS = XML.SUCCESS
> 0033:             CRT "XDOMGetNodeValue Success"
> 0034:          CASE STATUS = XML.ERROR
> 0035:             CRT "XDOMGetNodeValue Error"
> 0036:             GOSUB DISPLAY.XML.ERROR ; STOP
> 0037:          CASE STATUS = XML.INVALID.HANDLE
> 0038:             CRT "XDOMGetNodeValue Invalid Handle"
> 0039:             GOSUB DISPLAY.XML.ERROR ; STOP
> 0040:       END CASE
> 0041: !
> 0042:       CRT 'nodeValue = ':nodeValue
> 0043: !
> 0044:       STOP
> 0045: !
> 0046: DISPLAY.XML.ERROR:
> 0047:       STATUS = XMLGetError(errorCode, errorMessage)
> 0048:       CRT "errorCode = ":errorCode
> 0049:       CRT "errorMessage = ":errorMessage
> 0050:       RETURN
> Bottom at line 50.
> ----: Q
> 
> 
> When I run the program the XDOMGetNodeValue function always
> return an erro code 28.
> 
>> RUN TEST.BP TEST.XDOM
> XDOMOpen Success
> XDOMLocate Success
> XDOMGetNodeValue Error
> errorCode = 28
> errorMessage = No requested data was available.
> 
> 
> I have tested this program on both UniVerse 10.2.7 running on HP-UX
> 11.23 and also UniVerse 10.1.18 on a Windows XP workstation but I got
> the same error code 28 on both platforms.
> 
> It would be greatly appreciated if anyone can point out if I made any
> mistake using the XDOM API or if there is a better way to parse XML
> file using XPath in Universe Basic.
> 
> Thank you.
> Jason
> _______________________________________________
> U2-Users mailing list
> U2-Users@listserver.u2ug.org
> http://listserver.u2ug.org/mailman/listinfo/u2-users
_______________________________________________
U2-Users mailing list
U2-Users@listserver.u2ug.org
http://listserver.u2ug.org/mailman/listinfo/u2-users

Reply via email to