Reading data from an XML file in E3.

1) Introduction

This article shows you how to collect data from an XML file.

2) XML file

XML (EXtensible Markup Language) is a format for creating documents where data is organized hierarchically. It is frequently present in formatted text documents, vector images, or databases. Its main purpose is to make it easier to share information on the internet.

In this article, we will use an XML file with the following structure:

The first line in this file shows Elipse section. This section has two child elements: Company and Data. Data has the information on the company.

3) Script to read the file

To access this information in E3, you will need to create the DOMDocument object, which will grant access to the file’s methods and properties. You will need to set up async property as false.

set docxml = createobject(“MSXML2.DOMDocument”)

docxml.async = false

The Load method will load the desired XML document:

docxml.load(“.\Test.xml”)

From this point on, you will be able to access the elements in the XML file via SelectSingleNode method, which will grant access to the informed element.

set EleElipse = docxml.SelectSingleNode(“Elipse/Company”)

However, to access its value, you must use Text method:

company = EleElipse.Text

To access the child elements in Data, you will need to use ChildNodes method, and pass the child element’s index:

set EleChild = EleData.ChildNodes(0)
rua = EleChild.Text

The whole script:


4) Demo application

Attached to this article are both a demo application (developed with E3 version 4.0 build 225) and the XML file (in the same folder as the .dom and .prj files).

A ListBox object that shows the returned data and a button with the script to be executed were added to the screen.

5) References

1. Microsoft MSDN Library Online

2. W3Schools

3. ScriptBrasil

Attachments:

Reading_XML

Print Friendly, PDF & Email

Este artigo foi útil? Was this helpful?

Classificação média - Average rating 0 / 5. Count: 0

Leave a Reply

Your email address will not be published.Required fields are marked *