Hi jerry,

If you don't want to use xmapping system, you can do like this :

1 - store xml clob directly under universe (one record is one xml clob)
2 - define xpaths expression to adress the data you need from the xml clob
3 - call one subr to extract the xpath's values

How to write a xpath stmt : http://www.w3schools.com/xpath/xpath_syntax.asp 

You can use it as a subr call 

XMLDATA = ...
CALL 
IN.XDOM.XPATHS(RESULT,XMLDATA,"/ONIXmessage/Product/MediaFile[2]/MediaFileLink[text()]",errorcode)

or from a i-type
EXTRACT(@RECORD,...,0,0);SUBR("IN.XDOM.XPATHS",@1,"/ONIXmessage/Product/MediaFile[2]/MediaFileLink[text()]",'')

The code:
******************************************************************
* Input: xml.doc : le fichier xml (ex : FSO.IN.XML/test.xml)
*        xpath<AM> : les xpaths (ex : 
'/bookstore/book[price>35.00][*]/title[*]')
*                    Dans l'exemple ci-dessous, on veut les titres de tous les 
livres
*                    du document xml dont le prix est > que 35
*                     
* 
*    <?xml version="1.0" encoding="ISO-8859-1"?>
*    <bookstore>
*      <book>
*        <price>29.99</price> 
*        <title lang="fr">Harry Potter</title>
*        <type>titi</type>         
*      </book>
*      <book>
*        <price>37.95</price>
*        <title lang="eng">Learning XML</title>
*        <title lang="eng">XML POUR LES NUL</title>
*        <type>toto</type>        
*      </book>
*       <book>
*        <price>42.95</price>
*        <title lang="fr">Martine à la ferme</title>
*        <type>toto</type>        
*      </book>
*    </bookstore>  
*       
*                     
* Output: p.result : les noeuds du xpath
*   (ex : p.result<1,1> = <title lang="eng">Learning XML</title>
*         p.result<1,2> = <title lang="eng">XML POUR LES NUL</title>
*         p.result<2,1> = <title lang="fr">Martine à la ferme</title>
*         Si on a plusieurs XPath, les p.result de chaque XPath sont séparé par 
des "|"
*  
*         p.err : err<1>: numérique, 0 si OK (XML.SUCCESS)
*                 err<2>: message éventuel
******************************************************************
subroutine IN.XDOM.XPATHS(p.result,xml.doc,xpath,p.err)
$INCLUDE UNIVERSE.INCLUDE XML.H
err.xpath = 0
p.result = ""
p.err = 0

pos = index(xml.doc,"<",1)
if pos > 0 then
  Status = XDOMOpen(xml.doc,XML.FROM.STRING,XDDO)
end else
  xml.doc = CHANGE(xml.doc," ","/")
  xml.doc = CHANGE(xml.doc,"\","/")
  Status = XDOMOpen(xml.doc,XML.FROM.FILE,XDDO)
end  
if Status # XML.SUCCESS then
    Status2 = XMLGetError(code,valeur)
    p.err<1> = Status
    p.err<2> = "Impossible d'ouvrir le DOM xml [":code:"] : ":valeur
    return
end 

nbrXpath = DCOUNT(xpath,@AM)
for i = 1 to nbrXpath
  para.xpath = xpath<i>
  CALL IN.XDOM.XPATH(result.xpath,xml.doc,para.xpath,XDDO,err.xpath)
  if err.xpath = 0 then
    if p.result = "" then
      p.result = result.xpath
    end else
      p.result := @AM:result.xpath
    end    
  end else
    gosub CLOSE.DOM
    p.err = err.xpath
    return
  end    
next i

gosub CLOSE.DOM

return


CLOSE.DOM:
Status = XDOMClose(XDDO)
if Status # XML.SUCCESS then
  p.err<1> = Status
  p.err<2> = "Impossible de fermer le DOM xml"
  return
end
return

end

*-------------------------------------------------------------------

subroutine IN.XDOM.XPATH(p.result,xml.doc,xpath,dom,p.err)
* ATTENTION TO BE CALLED FROM ...XPATHS

$OPTIONS PICK
$INCLUDE UNIVERSE.INCLUDE XML.H
INCLUDE DMSKELCODE COMMON

EQU EQU_TEXT TO "[text()]"
EQU EQU_MAX_ERR TO 5
p.err = 0
p.result = ""
err = 0

size = dcount(xpath,"*")
if size > 1 then
  cpt.err = 0
  for i = 1 to 999
    xpath2 = CHANGE(xpath,"*",i,1) 
    CALL IN.XDOM.XPATH(p.result2,xml.doc,xpath2,dom,err)
    if err<1> # 0 and err<1> # 10 then
      p.err = err
      return
    end else  
      if err<1> = 10 then
        return
      end else
        pos = index(xpath,EQU_TEXT,1) 
        if pos > 0 then
          if p.result2 = "" then
            cpt.err = cpt.err + 1
          end else
            p.result2 = LOWER(p.result2)
            p.result<-1> = p.result2    
            cpt.err = 0
          end 
        end else
          if p.result2 = "" then
            cpt.err = cpt.err + 1
          end else
            p.result2 = LOWER(p.result2)
            p.result<-1> = p.result2 
            cpt.err = 0
          end 
        end 
      end
      if cpt.err > EQU_MAX_ERR then
        return   
      end  
    end   
  next i
end else
  ** on test pour savoir si on  veut le text du noeud ou le noeud
  gosub TRT.ONE.XPATH
  if p.err<1> = 0 then
      p.result = value
  end    
end   
return

**TRAITEMENT D'UN XPATH
TRT.ONE.XPATH:
  value = ""
  pos = index(xpath,EQU_TEXT,1) 
  if pos > 0 then
    ** si on veut le texte
    xpathTxt = change(xpath,"[text()]","")
    Status = XDOMLocate(dom,xpathTxt,"",XROOT)
    if Status = XML.SUCCESS then
      Status = XDOMLocate(XROOT,"text()","",NODEH)
      if Status = XML.SUCCESS then
        Status = XDOMGetNodeValue(NODEH, value)
        value = change(value,char(13),"") 
        value = change(value,char(10),"")    
        HANDLE = XROOT
        gosub CLOSE.DOM
      end  
      HANDLE = NODEH
      gosub CLOSE.DOM
    end else
      Status2 = XMLGetError(code,valeur)
      p.err<1> = code
      p.err<2> = valeur
    end   
    
  end else
    ** si on veut le noeud
    Status = XDOMLocate(dom,xpath,"",XNODE)
    if Status = XML.SUCCESS then
       Status = XDOMWrite(XNODE, value, XML.TO.STRING)
       *value = XNODE
    end  else
      Status2 = XMLGetError(code,valeur)
      p.err<1> = code
      p.err<2> = valeur
    end   
    HANDLE = XNODE
    gosub CLOSE.DOM
  end  
  return
  
CLOSE.DOM:
Status = XDOMClose(HANDLE)
if Status # XML.SUCCESS then
  p.err<1> = Status
  p.err<2> = "Impossible de fermer le DOM xml"
  return
end
return
    
*--------------------------------------------
    
**************************

> -----Message d'origine-----
> De : u2-users-boun...@listserver.u2ug.org [mailto:u2-users-
> boun...@listserver.u2ug.org] De la part de Jerry Banker
> Envoyé : vendredi 14 octobre 2011 20:02
> À : U2 Users Group Technical
> Objet : [U2] XML and UV
> 
> 
> I've been looking through the documentation that comes with UniVerse trying
> to find a subroutine that can be used in a UniBasic program that will take an
> XML document, in any of the many ways of formatting XML, and return the file,
> field, and data. Do you have to build a program to do this for each file you
> recieve or is there a built in subroutine that will parse any document and 
> give
> you the data you need.
> 
> Jerry
> _______________________________________________
> 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