This is documentation for Mathematica 5, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)

Documentation / Mathematica / Add-ons & Links / XML Capabilities / Importing XML /

XMLGetString

The XMLGetString function can be used to import an XML string as SymbolicXML. It is very similar to the ImportString function, in that XMLGetString[string] is equivalent to ImportString[string, "SymbolicXML"].

In[10]:=

Out[10]=

Note that XMLGetString exists only in the XML`Parser` context. Hence, you must use the full name of the function, XML`Parser`XMLGet, when doing an evaluation. To use the function without the context name prefix, you must first add the XML`Parser` context to your context path.

The advantage of using XMLGetString is that it accepts a pre-initialized parser object as its second argument.

    XMLGetString[file, XMLParserObject]

Initializing the parser involves loading a DTD into memory either from a URL or a local file. This only needs to be done once in each kernel session. Subsequent references to the DTD are then processed much faster because the DTD has already been read and parsed. For more information on initializing the parser, see InitializeXMLParser.

For example, the following command loads the XML package and then pre-initializes the parser according to the XHTML DTD located at the specified URI. In this example, the pre-initialized parser is given the name XHTMLParser.

In[11]:=

Out[11]=

Now that the parser is initialized, we import an XML string. The string is validated with respect to the DTD stored in XHTMLParser by setting "ValidateAgainstDTD" RuleTrue. The option Valid RuleTrue in the output, which indicates that the XML input string was valid XML with respect to the XHTML DTD.

In[12]:=

Out[12]=

You can also specify ConversionOptions for XMLGetString to control the various details of the import process. The conversion options for XMLGetString are the same as those for ImportString. However, the syntax for specifying conversion options is slightly different. The conversion option can be specified directly in the XMLGet function such that

    XMLGetString[string, option1 Rule value1, option1 Rule value2,...]

is equivalent to

    ImportString[string,"SymbolicXML", ConversionOptions Rule {option1 Rule value1, option1 Rule value2,...}]

For more information on the conversion options available for importing XML, see Import Conversion Options.