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

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

Verifying SymbolicXML Syntax

You can use the function XML`SymbolicXMLErrors to find errors with a SymbolicXML expression. This function returns a part specification which you can use with functions like Part or Extract to access the problematic part of your SymbolicXML expression. Let us return to the American League hitters from our earlier example.

In[95]:=

We saw above that there were PlayerRecord nodes for which the Salary node contained the string "#N/A". Suppose we decide that any player whose salary is not available to use must be making $1,000,000. However, when we do our transformation, we make an easily overlooked mistake.

In[96]:=

We have now created incorrect SymbolicXML. We have put the string "1000000" as the third element of the XMLElement expression, rather than a list containing that string. Suppose we did not know this, though, and that later on we find that Export produces errors when we try to write our modified XML to a file. We can use SymbolicXMLErrors to find the problematic expressions.

In[97]:=

Out[97]=

Notice that we first received XMLElement::name messages. These are our first indication that something is wrong, and we would have received these messages with just about any other function that processes SymbolicXML. The output of SymbolicXMLErrors, however, tells us exactly where something went wrong. ALerrors now contains a list of part specifications where the errors occurred. Here we examine the first error.

In[98]:=

Out[410]=

In[99]:=

Out[99]=

In[100]:=

Out[100]=

This problem is easy enough to fix.

In[101]:=

Out[101]=

We can see that the rest of the errors are of the same nature.

In[102]:=

Out[102]=

By using Map, we can fix the rest of the errors in the same way.

In[103]:=

Out[103]=

We can then verify that we have fixed our mistake using SymbolicXMLErrors again.

In[104]:=

Out[104]=