It allows XML files or XML strings to be read.
A variable of a data type called XMLReader must be defined in order to read the content of an XML file or XML string from a GeneXus object. The methods and properties needed to obtain the information concerning the nodes that make it up must then be invoked.
The basic idea is that there is a Read() method that behaves like a cursor moving forward through the file, one node at a time. Using some properties such as Name and Value, it is possible to obtain the data for a node, in this case, its name and value. Thus, the Read() method is used to “navigate” through the document in a sequential way, obtaining the information on the different nodes.
Say we have the following XML document, called Meeting.xml:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<MEETING Date="06/03/01">
<DATE>06/03/01</DATE>
<!—Meeting description-->
<! [ CDATA [ Meeting of the application development team.
The meeting was held on Friday, 9.30 a.m. ] ] >
<MEMBERS>
<MEMBER>Peter</MEMBER>
<MEMBER>Laura</MEMBER>
<MEMBER>John</MEMBER>
<MEMBER>Diana</MEMBER>
</MEMBERS>
<TASKS>
<TASK>
<PERSON_IN_CHARGE>Peter</PERSON_IN_CHARGE>
<! [ CDATA [ Write the application’s documentation ] ] >
</TASK>
<TASK>
< PERSON_IN_CHARGE >Diana</ PERSON_IN_CHARGE >
<! [ CDATA [ Meet with clients ] ] >
</TASK>
<TASK>
< PERSON_IN_CHARGE >Laura</ PERSON_IN_CHARGE >
<! [ CDATA [ Write user’s manual ] ] >
</TASK>
<TASK>
< PERSON_IN_CHARGE >John</ PERSON_IN_CHARGE >
<! [ CDATA [ Document the specifications ] ] >
</TASK>
</TASKS>
</MEETING>
The following GeneXus procedure reads the file and obtains the members attending the meeting:
&XMLReader.Open('Meeting.xml')
&XMLReader.ReadType(1, 'MEMBERS')
&XMLReader.Read()
Do While &XMLReader.Name <> 'MEMBERS'
&MEMBER = &XMLReader.Value
&XMLReader.Read()
Enddo
&XMLReader.Close()
The following GeneXus procedure reads the file and obtains the tasks of a member attending the meeting:
&XMLReader.Open('Meeting.xml')
&success = &XMLReader.ReadType(1,'PERSON_IN_CHARGE')
Do While &XMLReader.Value <> &MEMBER
&success = &XMLReader.ReadType(1,'PERSON_IN_CHARGE')
If &success = 0
Exit
Endif
Enddo
If &success <> 0
&XMLReader.Read()
&tasks = &XMLReader.Value
Else
&tasks = Nullvalue(&tasks)
Endif
&XMLReader.Close()
When a property or method is used to assign a file's path (or URL) do not use user's inputs concatenations or sanitize the user's entries to avoid path traversal or path manipulation vulnerability risks.