Hack 8 Test XML Documents Online

figs/beginner.gif figs/hack8.gif

Are your XML documents syntactically correct? Find out how and where to check XML documents using online resources.

Several web sites allow you to test your XML documents online to make sure that they are well-formed and/or valid. This hack introduces three such sites: RUWF, RXP, and Brown University's XML validation form.

1.9.1 RUWF

One site that does well-formedness checks is XML.com's RUWF?Are You Well-Formed? (http://www.xml.com/pub/a/tools/ruwf/check.html)?which is implemented in Perl using XML::Parser (http://www.perl.com/pub/a/1998/11/xml.html). RUWF accepts a URL for an XML document or allows you to paste an XML document into a text box.

Figure 1-14 shows a copy of time.xml pasted into the text box, and Figure 1-15 shows the result of clicking the RUWF? button. (You could also test an online copy of time.xml, http://www.wyeast.net/time.xml, by entering the URL into the "Your URL" text box.)

Figure 1-14. XML.com's RUWF

Figure 1-15. Results of checking time.xml with RUWF

1.9.2 RXP

Richard Tobin of the University of Edinburgh has created RXP, a validating XML processor that is available online (http://www.cogsci.ed.ac.uk/~richard/xml-check.html) or from the command line [Hack #8].

As mentioned earlier, the document time.xml is available on my web site at http://www.wyeast.net/time.xml. Figure 1-16 shows you how to check this document for well-formedness using the online version of RXP. Enter the URL in the text box, and then click the button labeled "check it."

The result is displayed as canonical XML (http://www.w3.org/TR/xml-c14n) in Figure 1-17. Canonical XML defines a method for outputting XML in a consistent, reliable way, leaving some things behind in output, such as the XML declaration and, optionally, comments.

Figure 1-16. RXP online

Figure 1-17. Results of checking time.xml with RXP online

You can also use this form to check a document for validity. The document shown in Example 1-11, online.xml, is located at http://www.wyeast.net/online.xml.

Example 1-11. online.xml
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE time SYSTEM "http://www.wyeast.net/time.dtd">


<!-- a time instant -->

<time timezone="PST">





    <atomic signal="true"/>


Its document type declaration references the DTD time.dtd, which is also available online. Place the URL http://www.wyeast.net/online.xml in the URL text box. Click the "validate?" checkbox below the URL text box, then click the "check it" button. The well-formedness and validity checks should report no errors.

1.9.3 Brown University's Validation Form

Brown University's Scholarly Technology Group (STG) provides an online validation form at http://www.stg.brown.edu/service/xmlvalid/. Naturally, it does a well-formedness check as well because a valid XML document must also be well-formed. This form allows you to check and validate a local file, a URL, or a pasted document. Place the URL http://www.wyeast.net/online.xml in the form as shown in Figure 1-18, then click the Validate button. The result is shown in Figure 1-19.

Figure 1-18. Brown University's XML validation form

Figure 1-19. Results of validating online.xml with Brown University's XML validation form

If you have Internet access, these online tools are an easy, no-fuss way to check XML documents for well-formedness and validity.