Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
XML Adapter
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
XML, XSD
Titre:
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Divers
Thread ID:
01095559
Message ID:
01433010
Vues:
64
I needed to look at this again, and found something strange. When I run the sample below, then table 4 shows the date information, but not the
<organisasjonnummer>
<organisasjonsnummer registreringsDato="1995-02-19">939194517</organisasjonsnummer>
The field with the value 939194517 does not show in the table.

I have VFP 9.0 SP 2.

What is wrong?



>>Can you please help me with some code to get the table-info into cursors from this XML?
>
>Hi Einar,
>
>They've already created/defined a schema for the XML so the code is pretty straight-forward. Basically munge the XML so it is compliant with what the XMLAdapter expects and add on the schema. Here's some runnable code that should get you started... note that the schema is pulled over the web with RetrieveSchema() function and the XML was tossed into a variable in the RetrieveXML() function. You could have used FILETOSTR() or even pulled the XML across the web... the important part is just to get it into a variable that you can use. In any event, cut-n-paste the code below and run it from within VFP 9 (modify it to suit your needs - I'm just giving you the basic idea here).
>
>
>LOCAL loXMLAdapter, loBrowser, lcXSD, lcXMLContent, lcXMLHeader, lcXMLFooter
>
>lcXMLHeader = GetHeader()
>lcXSD = RetrieveSchema("http://ftp2.brreg.no/xml/skjema/grunndata/2004/04/28/hentBasisdataMini.xsd")
>lcXMLContent = RetrieveXML()
>lcXMLFooter = GetFooter()
>
>oXMLAdapter = NEWOBJECT('XMLAdapter')
>oXMLAdapter.LOADXML(lcXMLHeader + lcXSD + lcXMLContent + lcXMLFooter)
>
>CLOSE DATABASES ALL
>SET STEP ON
>oXMLAdapter.TABLES(1).TOCURSOR && Understatusmelding
>*!* no fields defined for this element
>*!*	oXMLAdapter.TABLES(2).TOCURSOR
>oXMLAdapter.TABLES(3).TOCURSOR && Responseheader
>oXMLAdapter.TABLES(4).TOCURSOR && Organisasjonsnummer
>oXMLAdapter.TABLES(5).TOCURSOR && Navn
>oXMLAdapter.TABLES(6).TOCURSOR && Forretningsadresse
>oXMLAdapter.TABLES(7).TOCURSOR && Postadresse
>oXMLAdapter.TABLES(8).TOCURSOR && Melding
>SET
>
>*****************************
>FUNCTION GetHeader()
>*****************************
> LOCAL lcHeader
> TEXT TO lcHeader NOSHOW
><?xml version="1.0" encoding="utf-8" ?>
><VFPDataSet>
> ENDTEXT
> RETURN lcHeader
>ENDFUNC
>
>*****************************
>FUNCTION GetFooter()
>*****************************
> LOCAL lcFooter
> TEXT TO lcFooter NOSHOW
></VFPDataSet>
> ENDTEXT
> RETURN lcFooter
>ENDFUNC
>
>*****************************
>FUNCTION RetrieveXML()
>*****************************
>LOCAL lcReturn
>TEXT TO lcReturn NOSHOW PRETEXT 7
><grunndata xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ftp2.brreg.no/xml/skjema/grunndata/2004/04/28/hentBasisdataMini.xsd">
>	<responseHeader prossessDato="2006-02-10" tjeneste="hentBasisdataMini">
>		<orgnr>939194517</orgnr>
>		<hovedStatus>0</hovedStatus>
>		<underStatus>
>			<underStatusMelding kode="0">Data returnert</underStatusMelding>
>			<underStatusMelding kode="1020">Enhet 939194517 har ikke postadresse</underStatusMelding>
>		</underStatus>
>	</responseHeader>
>	<melding tjeneste="hentBasisdataMini">
>		<organisasjonsnummer registreringsDato="1995-02-19">939194517</organisasjonsnummer>
>		<navn registreringsDato="1988-11-16">
>			<navn1>MICLIS AS</navn1>
>		</navn>
>		<forretningsAdresse registreringsDato="1999-05-19">
>			<adresse1>Bjørnstjerne Bjørnsons Gate 4</adresse1>
>			<postnr>2609</postnr>
>			<poststed>LILLEHAMMER</poststed>
>			<kommunenummer>0501</kommunenummer>
>			<kommune>LILLEHAMMER</kommune>
>			<landkode>NOR</landkode>
>			<land>Norge</land>
>		</forretningsAdresse>
>	</melding>
></grunndata>
>ENDTEXT
>RETURN lcReturn
>ENDFUNC
>
>*****************************
>FUNCTION RetrieveSchema(tcURL)
>*****************************
> #DEFINE INTERNET_OPEN_TYPE_PRECONFIG 0
> #DEFINE SYNCHRONOUS 0
> #DEFINE INTERNET_FLAG_RELOAD 2147483648
>
> DECLARE INTEGER InternetOpen IN WININET STRING Agent, ;
>  INTEGER AccessType, STRING ProxyName, ;
>  STRING ProxyBypass, INTEGER Flags
>
> DECLARE INTEGER InternetOpenUrl IN WININET ;
>  INTEGER hInternetSession, STRING Url, STRING Header, ;
>  INTEGER HeaderLength, INTEGER Flags, INTEGER Context
>
> DECLARE INTEGER InternetReadFile IN WININET INTEGER file, ;
>  STRING @Buffer, INTEGER NumberOfBytesToRead, INTEGER @BytesRead
>
> DECLARE SHORT InternetCloseHandle IN WININET INTEGER hInst
>
> LOCAL lcAgent, lhInternetSession, lhFile, llOK, lnReturn, lcReadBuffer, lnBytesRead, lcRetVal
>
> lcAgent = "VFP RSS 2.0 Reader"
> lhInternetSession = InternetOpen(lcAgent, INTERNET_OPEN_TYPE_PRECONFIG, "", "", SYNCHRONOUS)
>
> IF lhInternetSession = 0
>  ? "Problem Encountered: Internet session cannot be established"
> ELSE
>  lhFile = InternetOpenUrl( lhInternetSession, tcURL, '', 0, INTERNET_FLAG_RELOAD, 0)
>  IF lhFile = 0
>   ? "Problem Encountered: URL cannot be opened"
>  ELSE
>   lcRetVal = ""
>   llOK = .T.
>   
>   DO WHILE llOK
>    lcReadBuffer = SPACE(1500)
>    lnBytesRead = 0
>    lnReturn = InternetReadFile(lhFile, @lcReadBuffer, LEN(lcReadBuffer), @lnBytesRead)
>    IF (lnBytesRead > 0)
>     lcRetVal = lcRetVal + LEFT(lcReadBuffer, lnBytesRead)
>    ENDIF
>    llOK = (lnReturn = 1 AND lnBytesRead > 0)
>   ENDDO
>   
>   InternetCloseHandle(lhFile)
>   InternetCloseHandle(lhInternetSession)   
>   lcRetVal = Substr(lcRetVal, AT("<", lcRetVal, 3)) && strip the top node
>   RETURN lcRetVal
>  ENDIF
> ENDIF
> RETURN ""
>ENDFUNC
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform