Pikkola XML, tool No. 57

Read the XML. Then ask it something.

Paste a feed, a sitemap, an SVG or a pom.xml. It comes back indented, checked line by line, queried with XPath 1.0 and written as JSON. A mistake is marked at its line and column, and the document never leaves the tab.

5
examples
4
jobs
0
uploads

The studio

One document, four jobs

Indent it, check it, query it, or convert it. The source stays on the left, and the result follows every keystroke.

Source
Examples
Result

            

There is no result yet. Paste something on the left, or load one of the examples.

Checks

    Nothing leaves the tab

    No request, no account, no storage. The Content-Security-Policy sets connect-src to none, so the page could not upload a document even if it tried.

    Why the result can be trusted

    A formatter is only as good as its reader, and a query is only as good as the tree under it. Both are the browser's own, driven by the document you paste.

    01

    A scanner, not a pattern

    Opening and closing tags, attribute quoting, entity references, CDATA, comments, processing instructions and the doctype are read in order, each by its own rule. Nothing is guessed from a regular expression.

    02

    A mistake has a place

    Line and column come from the scanner position, so a tag that is never closed is marked where it opens, and a closing tag that does not match names the element that was open. Press a finding and the editor selects it.

    03

    XPath runs where the file already is

    The tree comes from the browser's XML parser and the query runs through document.evaluate. A node set, a number, a string and a boolean all come back, and a node result selects its place in the source.

    What the checker looks for

    Well formedness first, the rules that decide whether the document can be read at all. Every finding names a line and a column, and the line in the editor is marked when you press it.

    It checks the syntax and the namespaces, not a schema. A clean result means the document is well formed XML, not that it matches an XSD or that a service will accept it.

    • XML
      An element that is never closedThe opening tag is marked, not the end of the file, and the element that is still open is named so a long document gives a short answer.
    • XML
      A closing tag that does not matchA closing tag that arrives while another element is open is reported where it stands, with the name that was open, and the scan resumes from the matching element if there is one.
    • XML
      An attribute value without quotesAn unquoted value is refused at the attribute, and so is an attribute that appears twice on one element. Both are rules of the format, not preferences of this page.
    • XML
      An entity nobody declaredThe five XML entities, numeric character references and whatever the doctype declares are accepted. Any other name is reported at the character that starts it.
    • XML
      A second root elementXML has one root. A second top level element, or text beside the root, is reported at its first character instead of being quietly joined to the first.
    • XML
      A block that is never closedA comment needs -->, CDATA needs ]]>, a processing instruction needs ?> and a doctype needs >. A comment also cannot hold a double hyphen inside, as the specification says.

    Questions

    Is my document sent anywhere?

    No. There is no endpoint to send it to. The scanner, the writer and the converter are JavaScript files on this domain, the XPath query runs inside the page, and the Content-Security-Policy sets connect-src to none. Load the page once and it keeps working with the network off.

    Which parser is this?

    Two of them. A hand written scanner reads the document and marks the line and column, because the browser's parser only hands back a message. The tree used for formatting, XPath and JSON comes from the browser's own XML parser. Both are well formedness checkers: neither knows your schema.

    What does the formatter change?

    Whitespace between elements, and nothing else. A text node keeps every character it had, mixed content is left exactly as written, and CDATA, comments, processing instructions and the doctype are carried through. Minify removes the whitespace between elements only.

    How do attributes and text become JSON?

    An attribute becomes a key that starts with @, so id="3" is "@id": "3". Text becomes the value of an element when nothing else sits beside it, and goes under #text when attributes or child elements do. Repeated siblings become an array. Comments are left out and counted.

    Why does my XPath find nothing in a sitemap?

    A sitemap declares its default namespace, and XPath 1.0 has no default namespace, so //loc does not match it. Write //*[local-name()='loc'], or declare a prefix and query with it. The page knows every prefix the document declares, so a query that uses one of them works as written.

    Does it validate against an XSD or a DTD?

    No. It reads the document as XML: the syntax, the quoting and the namespaces. Whether the elements are the ones your XSD, your RSS reader or your Maven build expects is a different question, and a different tool.