Skip to content

Toro Cloud Dev Center

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.

Related articles

Please see the following articles for more information:

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:

├── ...
└── code
    └── xmlCursor
        ├── ReadLargeXmlFile.gloop
        └── models
            ├── Footer.model
            ├── Header.model
            └── Record.model

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

[Martini] Header details are: This is the header for 1000 random people records
[Martini] The name in record 1 is Wald Seys
[Martini] The name in record 2 is Rolland Matthieson
[Martini] The name in record 3 is Carey Nickolls
[Martini] The name in record 1000 is Justin Whye
[Martini] The trailer description is The trailer description goes here


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).

Gloop XML cursor in the Mapper view

  1. Open the service file to see comments. Make sure comments are also not hidden.