Publié : mar. 09/janv./2007 14:27
j'en prends note 

Forums PureBasic - Français
https://www.purebasic.fr/french/
Code : Tout sélectionner
_______________________________________________________________________________________________________________
Title: PureXML2 BETA
Version: 2.0 Beta3 (15-Jan-2007 01:36)
License: Free to use, greetings are welcome.
Author: Written by Flype, flype44(at)gmail.com.
Target: UserLibrary designed for PureBasic 4.02
OS: Microsoft Windows (Only tested on Windows XP SP2).
Descript: PureXML is a event-based XML parser, based on Expat 2.0.0.
No more DLL required - Small footprint (about 100Kb) !
Download: http://purebasic.myftp.org/?filename=files/44/PB4_UserLibs/UserLib_PB402_PureXML_V2_BETA.zip
_______________________________________________________________________________________________________________
List of functions :
PureXML_GetEngine() ; Retrieves the version of the internal XML engine.
PureXML_GetVersion() ; Retrieves the version of the PureXML UserLibrary.
PureXML_GetErrorString() ; Returns the error that has occurred as string.
PureXML_GetErrorCode() ; Returns the error that has occurred as errorcode.
PureXML_GetAttr(name.s) ; Returns the attribute value (by name).
PureXML_GetAttrCount() ; Returns the number of attributes.
PureXML_GetAttrName(index.l) ; Returns the attribute name (by index).
PureXML_GetAttrValue(index.l) ; Returns the attribute value (by index).
PureXML_GetBuffer() ; Returns the internal buffer string of the current parsing.
PureXML_GetColumn() ; Returns the column number of the current parsing position.
PureXML_GetDepth() ; Returns the tag's depth of the current parsing position.
PureXML_GetLine() ; Returns the line number of the current parsing position.
PureXML_GetPosition() ; Returns the byte-offset of the current parsing position.
PureXML_GetBase() ; Returns the base for resolving relative URLs.
PureXML_GetCDATA() ; Returns the CDATA Section of the current element.
PureXML_GetCharData() ; Returns the characters data of the current element.
PureXML_GetName() ; Returns the name of the current element.
PureXML_GetPath() ; Retrieves the path of the current element.
PureXML_GetStatus() ; Returns the parsing status between 0, 1, 2, 3.
PureXML_SetBase(base.s) ; Specify the base to be used for resolving relative URLs.
PureXML_SetEncoding(encoding.s) ; Specify the encoding type between US-ASCII, UTF-8, UTF-16, ISO-8859-1.
PureXML_ParseFile(fileName.s) ; Parse a XML document.
PureXML_ParseString(xmlString.s) ; Parse a XML string.
PureXML_ParseUrl(url.s) ; Parse a XML url.
PureXML_ParseResume() ; Resumes the current parsing, if suspended with PureXML_Stop(#True).
PureXML_ParseStop([resumable.l]) ; Stops the current parsing.
_______________________________________________________________________________________________________________
List of PureXML Handlers :
PureXML_SetAttributeHandler(*hProcedure) ; PureXML Handler: Attribute (name, value) of an element.
PureXML_SetCDataSectionHandler(*hProcedure1, *hProcedure2) ; PureXML Handler: Start and End of a CDATA Section.
PureXML_SetCharacterDataHandler(*hProcedure) ; PureXML Handler: Characters data between two elements.
PureXML_SetCloseHandler(*hProcedure) ; PureXML Handler: End of an element.
PureXML_SetCommentHandler(*hProcedure) ; PureXML Handler: Comments.
PureXML_SetDefaultHandler(*hProcedure) ; PureXML Handler: Default.
PureXML_SetElementHandler(*hProcedure1, *hProcedure2) ; PureXML Handler: Start and End of an element.
PureXML_SetEndCDataSectionHandler(*hProcedure) ; PureXML Handler: End of a CDATA Section.
PureXML_SetOpenHandler(*hProcedure) ; PureXML Handler: Start of an element.
PureXML_SetStartCDataSectionHandler(*hProcedure) ; PureXML Handler: Start of a CDATA Section.
PureXML_SetXmlHandler(*hProcedure) ; PureXML Handler: Xml Declaration.
_______________________________________________________________________________________________________________
PureXML Handlers syntax :
Procedure myAttribute(name.s, attrName.s, attrValue.s)
EndProcedure
Procedure myCharacterData(name.s, string.s, length.l)
EndProcedure
Procedure myComment(name.s, string.s, length.l)
EndProcedure
Procedure myDefault(name.s, string.s, length.l)
EndProcedure
Procedure myEndElement(name.s, depth.l)
EndProcedure
Procedure myEndCDataSection(name.s, string.s, length.l, position.l)
EndProcedure
Procedure myStartCDataSection(name.s, position.l)
EndProcedure
Procedure myStartElement(name.s, depth.l)
EndProcedure
Procedure myXml(xml_version.s, xml_encoding.s)
EndProcedure
_______________________________________________________________________________________________________________
Best Regards, flype 2007.
Code : Tout sélectionner
Global result$
Procedure.l Extract_From_IpPages(name.s, string.s, length.l)
Select name ; tag name
Case "ip": result$ + "IP V4: " + #TAB$ + string + #CRLF$
Case "ip_long": result$ + "IP: " + #TAB$ + string + #CRLF$
Case "ipv6": result$ + "IP V6: " + #TAB$ + string + #CRLF$
Case "host": result$ + "HOST: " + #TAB$ + string + #CRLF$
Case "isp": result$ + "ISP: " + #TAB$ + string + #CRLF$
Case "country": result$ + "CTRY: " + #TAB$ + string + #CRLF$
EndSelect
EndProcedure
If MessageRequester("Question", "Resolves your IP Address from `ippages.com` ?", #MB_OKCANCEL|#MB_ICONQUESTION) = #IDOK
PureXML_SetCharacterDataHandler(@Extract_From_IpPages())
If PureXML_ParseUrl("http://www.ippages.com/xml/")
If MessageRequester("Copy the result to the clipboard ?", result$, #MB_OKCANCEL|#MB_ICONINFORMATION) = #IDOK
SetClipboardText(result$)
EndIf
Else
MessageRequester("Error", PureXML_GetErrorString(), #MB_ICONERROR)
EndIf
EndIf
Code : Tout sélectionner
Structure PRODUCT
id.s
name.s
price.s
desc.s
EndStructure
Global NewList product.PRODUCT()
Procedure ProductInfo_StartElement(name.s, depth.l)
If name = "product"
If AddElement(product())
product()\id = PureXML_GetAttr("id")
EndIf
EndIf
EndProcedure
Procedure ProductInfo_EndElement(name.s, depth.l)
Select name
Case "name": product()\name = PureXML_GetCharData()
Case "price": product()\price = PureXML_GetCharData()
Case "desc": product()\desc = PureXML_GetCharData()
EndSelect
EndProcedure
PureXML_SetElementHandler(@ProductInfo_StartElement(), @ProductInfo_EndElement())
If PureXML_ParseString(xml$)
ForEach product()
Debug "id = " + product()\id
Debug "name = " + product()\name
Debug "price = " + product()\price
Debug "desc = " + product()\desc
Debug ""
Next
EndIf