PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • Declaring an xmlDocument variable
  • Properties specific to the description of the xmlDocument variables
  • Using the indirection on the paths in an XML document
  • Functions that use the xmlDocument variables
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
The xmlDocument type is used to handle an XML file. The characteristics of this file can be defined and modified by several WLanguage properties.
Note: See Declaring a variable for more details.
Versions 17 and later
iPhone/iPad This type of variable is now available for the iPhone/iPad applications.
WINDEVJava This type of variable is now available for the Java applications.
Android This type of variable is now available for the Android applications.
Android This type of variable is now available from Android version 2.2.
New in version 17
iPhone/iPad This type of variable is now available for the iPhone/iPad applications.
WINDEVJava This type of variable is now available for the Java applications.
Android This type of variable is now available for the Android applications.
Android This type of variable is now available from Android version 2.2.
iPhone/iPad This type of variable is now available for the iPhone/iPad applications.
WINDEVJava This type of variable is now available for the Java applications.
Android This type of variable is now available for the Android applications.
Android This type of variable is now available from Android version 2.2.
Versions 21 and later
Universal Windows 10 App This type of variable is now available in Universal Windows 10 App mode.
New in version 21
Universal Windows 10 App This type of variable is now available in Universal Windows 10 App mode.
Universal Windows 10 App This type of variable is now available in Universal Windows 10 App mode.
Example
// Example that is using the following XML file: play.xml
// <?xml version="1.0"?>
// <PLAY>
// <TITLE>Title of the play</TITLE>
//
// <PERSONAE>
// <PERSONA>A character</PERSONA>
// </PERSONAE>
//
// <ACT>
// <SCENE>
// <SPEAKER></SPEAKER>
// <LINE></LINE>
// </SCENE>
// </ACT>
// </PLAY>


// Declare an xmlDocument variable that is using a document template
RomeoAndJuliet is xmlDocument, description = "play.xml"

// Load an XML document from a file
RomeoAndJuliet = XMLOpen("romeo_and_juliet.xml", fromFile)

// Display the version number of the XML
Trace(RomeoAndJuliet..Version)

// Display the title of the play by accessing the nodes directly
Trace(RomeoAndJuliet.PLAY.TITLE)
Remarks

Declaring an xmlDocument variable

The xmlDocument variables can be declared by indicating a sample document (XML file) or a template document (XSD file). The structure of this document will be read by WINDEV, WEBDEV and WINDEV Mobile. Therefore, the automatic completion will be available for the names of nodes in the code editor.
To declare an xmlDocument variable with a sample document:
  1. Add the XML document into the project via one of the following methods:
    • select "Project .. List of project elements" and click the "Add" button.on the "Project" pane, in the "Project" group, click . The list of project elements is displayed. Click the "Add" button and select the XML document. on the "Project" pane, in the "Project" group, expand " List of elements" and click "List of project elements". The list of project elements is displayed. Click the "Add" button and select the XML document.
    • "Drag and Drop" the file to the "XML descriptions" folder of the "Project explorer" pane.
    • in the "Project explorer" pane, select the "XML descriptions" pane then "Import an XML description file" from the popup menu. in the "Project explorer" pane, select the "XML and XSD descriptions" pane then "Import an XML into this project" from the popup menu.
  2. The XML document appears in the "XML descriptions" folder of the project explorer. You have the ability to see its structure.The XML document appears in the "XML and XSD descriptions" folder of the project explorer. You have the ability to see its structure.
  3. Declare the variable as follows:
    <Variable Name> is xmlDocument, description =  <Document Name>

    <Document Name> can correspond to the name of sample document (with or without extension) or to the name of template document (with or without extension).
    Notes:
    • This declaration can be automatically obtained by dropping the name of the document from the project explorer.
    • When using a sample document, you also have the ability to use the following syntax:
      <Variable Name> is xmlDocument
      <Variable Name> = XMLOpen(<Document Name>
  4. You now have the ability to access the variable nodes by their names. These names are automatically proposed by the mechanism for automatic completion of the code editor.
Note: XMLSave is used to save the XML document. If an XSD file was used, it will be automatically taken into account.

Properties specific to the description of the xmlDocument variables

The following properties can be used to handle an xmlDocument variable:
NameType usedEffect
EncodingCharacter stringEncoding used for the character strings of the XML document. The UTF-8 encoding is used if this property is not specified or if it is set to "" (empty string). This is the case for example during a conversion into string with XMLBuildString.
RootNodeArray of xmlNodeArray of root nodes of the XML document.
A valid XML document must have a single root node. However, several nodes can be found at the root when building the document.
VersionCharacter stringVersion of the XML format. In most cases, this property is set to "1.0".
Note: These properties can be used with one of the following syntaxes:
  • <Variable Name>..<Property Name>
  • <Variable Name>.<Property Name>
AndroidJava Caution: The iteration order is not necessarily the order in which the attributes are declared in the document (in most cases, the attributes are listed in alphabetical order).

Using the indirection on the paths in an XML document

The indirection operators can be used to build the path of an element in an XML document.
Example:
sXMLDoc is string = [
<?xml version="1.0" encoding="UTF-8"?>
<Document>
<VersionInfo>
<Version>21</Version>
<Year>2016</Year>
</VersionInfo>
</Document>
]

xmlExample is xmlDocument = XMLOpen(sXMLDoc, fromString)

sParam is string = "WinDev_Param"

// Direct reading of information ...
Trace(xmlExample.Document.VersionInfo.Version)

// Reading with part of XML path found in a variable
// (idem if file item, window parameter, method, ...)
sParameter is string = "VersionInfo"
Trace ({"xmlExample.Document." + sParameter + ".Version"})

Functions that use the xmlDocument variables

XMLBuildStringRetrieves and formats the content of an XML document (created by XMLDocument and modified by the XML functions).
XMLOpenLoads an XML document from a file, a URL or a string in an xmlDocument variable.
XMLSaveSaves an XML document in a file.
XMLValidDocumentValidates an XML document from an XSD schema.
Note: The browse of an XMLDocument variable must be performed by using the FOR EACH syntax. XMLRead must not be used.
Minimum required version
  • Version 15
This page is also available for…
Comments
ler xml com XmdDocument
ler xml com XmdDocument

Nessa aula, vou mostrar como ler xml com XmdDocument
In this lesson, I will show how to read XML with XmlDocument
Dans cette leçon, je vais vous montrer comment lire XML avec XmlDocument


sDocumento is string=EDT_xml
//Vou abrir o xml // i Will open the xml // je vais ouvrir le xml
XMLDocument("xml",sDocumento)
XMLFind("xml",Null,XMLContinue+XMLChildItem)
//Acima exemplo do xml pegar chave nfe // Above example xml get key nfe // Au-dessus exemple xml obtenir nfe clé
EDT_ChaveNota=XMLRead("xml","/nfeProc/protNFe/infProt/chNFe")
//Vamos pegar numero nota fiscal // let-s take number invoice // prenons facture numéro
EDT_numero_nota=XMLRead("xml","/nfeProc/NFe/infNFe/ide/nNF")
//<?xml version="1.0" encoding="UTF-8"?>
//<nfeProc xmlns="http://www.portalfiscal.inf.br/nfe" versao="3.10">
//<NFe xmlns="http://www.portalfiscal.inf.br/nfe">
//<infNFe Id="NFe43160689054050000165550010011405341015943286" versao="3.10">
//<ide>
//<cUF>43</cUF>
//<cNF>01594328</cNF>
//<natOp>VENDA MERCADORIAS SUBST. TRIBUTARIA</natOp>
//<indPag>1</indPag>
//<mod>55</mod>
//<serie>1</serie>
//<nNF>1140534</nNF>
//<dhEmi>2016-06-24T00:00:00-03:00</dhEmi>
//Vamos pegar a data emissao// let´s get the date issuance // obtenons i´émission de date
s_data_emissao is string=XMLRead("xml","/nfeProc/NFe/infNFe/ide/dhEmi")
//2016-06-24
//1234567890
//Vou transformar data string em data// i´ll turn string date date // je vais chaîne de date jour tourne
d_data_emissao is Date=""
d_data_emissao..Day=s_data_emissao[[9 TO 10]]
d_data_emissao..Month=s_data_emissao[[6 TO 7]]
d_data_emissao..Year=s_data_emissao[[1 TO 4]]
EDT_data_emissao=d_data_emissao
//vou fazer o mesmo para cnpj e numero nota fiscal //i will do the same for cnpj number and invoice
// je vais faire la meme chose pour le numéro de cnpj et la facture
EDT_cnpj_emitente=XMLRead("XML","/nfeProc/NFe/infNFe/emit/CNPJ")
EDT_cnpj_destinatario=XMLRead("XML","/nfeProc/NFe/infNFe/dest/CNPJ")
IF EDT_cnpj_destinatario="" THEN
EDT_cnpj_destinatario="CPF:"+XMLRead("XML","/nfeProc/NFe/infNFe/dest/CPF")
END
EDT_valor_nota_fiscal=XMLRead("XML","/nfeProc/NFe/infNFe/total/ICMSTot/vNF")

//Blog com Video e exemplo
http://windevdesenvolvimento.blogspot.com.br/2016/07/curso-windev-xml-003-ler-xml-aula-2.html
https://www.youtube.com/watch?v=XzBwej31-Qg

De matos AMARILDO
Jul. 04 2016