Test XML Documents Online

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.

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.)

XML.com’s RUWF

Figure 1-14. XML.com’s RUWF

Results of checking time.xml with RUWF

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

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 #9] .

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.

RXP online

Figure 1-16. RXP online

Results of checking time.xml with 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">
    <hour>11</hour>
    <minute>59</minute>
    <second>59</second>
    <meridiem>p.m.</meridiem>
    <atomic signal="true"/>
</time>

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.

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.

Brown University’s XML validation form

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

Results of validating online.xml with 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.

Get XML Hacks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.