Reference Guide > X–Z Routines > XmlParse Function
  

XmlParse Function
Parses an XML file or an in memory XML document and builds an internal DOM tree which can be used in other XML functions. A DOM is a Document Object Model that XML parsers use to represent the contents of an XML document in memory in a manner that allows the contents to be queried and navigated.
Usage
document_id = XmlParse(document)
Input Parameters
document—A file name or an input string variable is required for parsing an XML document. By default, this parameter is assumed to be a string and will be processed as an in memory XML document. See the File keyword, which is used to indicate that this string is a file path.
Returned Value
document_id—A parsed document handle, used to identify this parsed document in other function calls. If the function fails, -1 is returned.
Keywords
DTD—A String containing the path to a file containing the DTD (Document Type Definition). This is a schema definition or description of the rules which a particular type of XML document is expected to adhere to. This is useful if you want to validate the document.
File—If present, the first input argument is processed as a file path (absolute or relative path).
Keep_Blanks—If present, the blank space in an XML document will not be ignored. This is useful if you intend to later write the XML document back out as a file and want to have it formatted with indents exactly as in the original document.
Validate—If present, the document will be validated. The format of the file will be validated against the schema defined in the DTD defined in the prolog of the document or provided in the DTD keyword. If any validation errors are found they will be printed and a value of –1 will be returned from XmlParse.
Discussion
Parses an XML file or an in-memory document and builds a DOM tree in memory. It will also validate a document against a DTD. The document ID returned from XmlParse is used as an input parameter to the routines XmlSetContext and XmlEvaluate.
Example 1
This example parses an XML file.
; Build a DOM tree from a file and return its handle in doc_id.
doc_id = XmlParse('xml-1_0/data/chart.xml', /File)
Example 2
This example parses an in-memory document.
; Build a DOM tree from the XML data in memory and
; return the tree handles in doc_id.
in_doc = '<?xml version="1.0"?>'+$ 
   '<Chart>' + '<ChartTitle>'+ $
   '<Attribute name="Title">Line Chart</Attribute>'+ $
   '<Attribute name="FontSize" value="14"/>'+ $
   '<Attribute name="FontStyle" value="3"/>'+ $
   '</ChartTitle>' + '</Chart>' 
doc_id = XmlParse(in_doc)
Example 3
This example validates an XML document against a given DTD.
doc_id = XmlParse('xml-1_0/data/chart.xml', $
   DTD='xml-1_0/data/chart.dtd', /Validate, /File)
Example 4
This example keeps the blank spaces that are present in the XML document.
doc_id = XmlParse('xml-1_0/data/chart.xml', /File, /Keep_Blanks)

Version 2017.0
Copyright © 2017, Rogue Wave Software, Inc. All Rights Reserved.