Skip to main content

%XML.TextReader In Action

Let's take a look at a small example using the %XML.TextReaderOpens in a new tab class. This example reads an XML document and prints all of its XML elements to the current device:

—Using %XML.TextReader—
Using %XML.TextReader
ClassMethod ShowElements(filename As %String)
{
    // Create an instance of %XML.TextReader (returned by reference)
    Set sc = ##class(%XML.TextReader).ParseFile(filename,.reader)

    If ($$$ISOK(sc)) {
        // Read all elements within the document
        While (reader.Read()) {
            If (reader.NodeType = "element") {
                Write reader.Name,!
            }
        }
    }
}

Let's take a closer look at this example.

FeedbackOpens in a new tab