examples
package: Reading a large XML file using an XML cursor
It is practical to use cursors when reading and writing large datasets, including files. The
examples
package demonstrates how to use an XML cursor to read a large XML file; simply
inspect the xmlCursor.ReadLargeXmlFile.gloop
service.
Try it!
In the Navigator, expand the examples
package and navigate to the
code
folder, then expand the xmlCursor
package. This package contains
models and services as shown below:
1 2 3 4 5 6 7 8 9 |
|
Open to inspect and run the xmlCursor.ReadLargeXmlFile.gloop
service to learn
how XML input cursors work line comments are provided for further explanation1.
This service opens an XML cursor that reads an XML file included in the examples
package
and writes out the contents of certain elements as they're processed.
Running the xmlCursor.ReadLargeXmlFile.gloop
service will provide an output similar to that shown below:
Output of ReadLargeXmlFile.gloop
1 2 3 4 5 6 7 |
|
Explanation
The example service provided demonstrates how easy and fast it is to read a large XML file using an XML cursor. Not
only does Gloop read the file as a cursor (as opposed to reading the entire file to memory),
Gloop allows you to choose which elements in the file to pass on in the cursor.
This allows you to pick-and-choose which parts of a large XML file you're interested in;
element names that aren't passed into the cursor are ignored.
In the example service the header
, record
, and trailer
element names are used.
The XML cursor provides two properties, a nodeName
string property, and a cursor
object, which is a data model representation of
the element and it's children (as shown below).
-
Open the service file to see comments. Make sure comments are also not hidden. ↩