You might have noticed that JSON has become a quite popular text format over the last years. Especially for everyone who is working in a Java environment. But how do you check your JSON instance documents in a convenient and standardized way like you can do for any XML file? For this purpose JSON Schema was introduced. In order to help people writing JSON schemas, XML ValidatorBuddy provides now special syntax-coloring for schema keywords and a built-in validator.

But how do you tell XML ValidatorBuddy that you are working on a JSON schema? Simply use the new “Quick Associations” pane which is available since version 4.3 and set the “Document is JSON Schema” checkmark. From this moment on the editor knows that this JSON file should be treated as JSON schema.

Set as JSON schema

JSON Schema check-box

You will notice that the way JSON syntax-coloring works changes immediately after telling XML ValidatorBuddy that this JSON is actually a schema file. All of the schema keywords are now green and all of the keywords are also present in the auto-completion. Just take a look how the GeoJSON schema is displayed in the editor:

GeoJSON schema in editor

GeoJSON schema file with syntax-coloring

You can see that keywords like “properties” or “description” appear in green, while arbitrary names like “longitude” are still in red. This improves the readability of the schema file in the editor a lot.

Auto-completion is a very important feature and helps tremendously on creating and editing any text-based standard. As you can see on the screenshot below, XML ValidatorBuddy provides a list of JSON schema keywords also for the auto-completion window:

auto completion for json schema

Auto-completion window for JSON schema

And how do I check my JSON instance document once the schema is ready? Simply enter the path to the JSON schema at the “JSON Schema” field of the “Quick Associations” pane when the JSON instance is the active document. Now the editor keeps a reference to the schema for this instance document. It is also possible to put a relative path here. So you can just enter the name of the schema, if both are located in the same folder. Whenever you use the “Validate against JSON Schema” command the schema content is either loaded from disk or directly taken from the editor and the validation results appear in the “Results” pane.

»crosslinked«

Share
, ,

HTML Tidy is a popular tool to clean up HTML markup. The tool can be very helpful to make HTML more readable and easier to maintain. In addition it is also easy to add HTML Tidy as an external tool to XML ValidatorBuddy. You can download HTML Tidy for Windows from here.

To add HTML Tidy as an external tool just go the Tools page of the Options dialog:

HTML Tidy as external tool

HTML Tidy as external tool

Where the options are:

  • “-i” to apply automatic indentation to the markup.
  • “-raw” to keep the character enconding (works for standard 8 bit encodings).
  • “-m” to do the modifications in-place directly in the original input file.

After this simple step you can apply HTML Tidy to any .html file from the File Explorer window in XML ValidatorBuddy. This can be very convenient if you have to process a large number of input files.

Share

The short answer is unzip the .xslx or .docx files which are just ZIP archives with some XML documents inside and convert them in XML ValidatorBuddy using the “Convert XML to JSON” command :-)

For Excel you will find the data of the single worksheets in the xl\worksheets folder within the .xslx archive. Extract the worksheet XML files wherever you want and open the document in XML ValidatorBuddy. The XML will be in one line but after you have converted it to JSON the output is pretty-printed and well-formed. So all you have to do afterwards is to save it on disk.

 

Share
, , ,

Sometimes people need to copy parts from an existing huge document into a new and smaller file. With XML ValidatorBuddy you can load and view really large XML (and other text) files using the Large File Viewer window. Here are the simple steps:

  1. Open the huge file in XML ValidatorBuddy using the Large File Viewer.
  2. Select the parts of the document you want to copy in the view. Here is something to consider: The whole document is not available at once. Therefore a copy-all operation only puts the currently loaded lines into the clipboard.
  3. Create a new document in XML ValidatorBuddy with Ctrl-N.
  4. Paste the content of the clipboard into the new file.

Although these steps are quite obvious you need to consider that the huge file is never loaded completely into the application. So it is not possible to select a range which exceeds the currently available text buffer. In this case simply select until you reach the end of the buffer. Paste the first part into the new document, go back to the Large File Viewer and scroll until new lines are loaded. Repeat to copy-paste from the huge document until you have everything you wanted also in the new file.

 

Share

Based on customer feedback I want to post some solutions for two very common Schematron checks. The first rule is an assertion to report if all values of an attribute are unique for all elements (within the same parent):

<iso:pattern id="unique name attributes">
 <iso:rule context="people">
    <iso:assert test="count(person) = count(person[not(@name=preceding-sibling::person/@name)])">
      Not all name attributes of the person elements are unique
    </iso:assert>
  </iso:rule>
</iso:pattern>

The second one is a check to see if all element values of a certain element (within the same parent) are unique:

<iso:pattern id="unique drawers">
  <iso:rule context="shelf">
    <iso:report test="count(drawer) != count(distinct-values(drawer))">
      Content of drawers not distinct
      <iso:value-of select="." />
    </iso:report>
  </iso:rule>
</iso:pattern>

 

Share

Whenever you create some JSON output and want to make sure that the generated file is really parsable you can take XML ValidatorBuddy to check one or many JSON files quickly with just a few clicks.

Just select the files you want to check in the File Explorer window of XML ValidatorBuddy and use the “Check if JSON well-formed” command from the JSON menu.

check json well-formed

Command to check well-formed JSON

And if we have some malformed JSON to check like here:

{
“root”: {
“span”: [ { "style": "font" }, 1, ]
}
}

we get the following error report:

json check results

Results of JSON well-formed check

This way you can easily make sure that your JSON files are also readable by other applications.

Share

Starting with release 4.0 of XML ValidatorBuddy the tool is also a XML to JSON converter. You can do conversions from XML to JSON and also from JSON to XML with a single click. To convert XML documents to JSON use the “Convert XML to JSON” command from the XML menu:

Convert XML to JSON

XML ValidatorBuddy will then convert all selected files from XML to JSON. Regardless of the file extension the conversion process assumes that all selected files are XML documents and XML ValidatorBuddy tries to convert them to the JSON file format. After a document has been converted, the tool also applies a JSON well-formed check to make sure that the generated output is readable JSON. You can also apply the JSON well-formed check separately on one or many files by using the “Check if JSON well-formed” command from the JSON menu.

The converted JSON document gets the same file title and has only the file extension replaced with .json. If there is already a file present with this name, the conversion is not executed and no document is written.

Use the “Convert JSON to XML” command from the JSON menu to convert any number of JSON documents to XML. The process is basically the same as the one from the XML to JSON conversion.

Share

 

Schematron is a powerful and useful technology to complement the common validation technologies like W3C Schemas and DTDs. However, it is often complicated to set up an environment to apply a Schematron schema to any number of files in an easy to use and simple way.

In this post I want to illustrate how easy it can be to apply a Schematron schema to many files at once. I will use the batch-task configuration dialog in XML ValidatorBuddy to setup and run a batch task which can also be used to create standard (W3C/DTD) batch validation tasks.

The Schematron schema will simply check and report how many child elements the root element has:

<?xml version="1.0" encoding="iso-8859-1"?>
<iso:schema xmlns="http://purl.oclc.org/dsdl/schematron" xmlns:iso="http://purl.oclc.org/dsdl/schematron" xmlns:sch="http://www.ascc.net/xml/schematron" queryBinding="xslt2" schemaVersion="ISO19757-3">
  <iso:title>ISO Schematron sample file.</iso:title>
  <iso:pattern id="root.elementcount">
    <iso:title>Count child elements of root</iso:title>
    <iso:rule context="/*">
      <iso:report test="count(*)">
        <iso:value-of select="count(*)"/> elements
      </iso:report>
      <iso:assert test="count(*) >= 1">A root element without any child elements</iso:assert>
    </iso:rule>
  </iso:pattern>
</iso:schema>

Use the “Configure and run a batch task…” command of the XML ValidatorBuddy desktop application to setup the batch. You can find this command in the context menu of the File Explorer tab or in the “File Explorer” menu.

Batch settings for Schematron in dialog

Schematron batch settings

Set the starting folder for the batch task in the “Start folder for batch” group.

To define a Schematron batch select “Schematron” at the “Parser to use:” field, check the “Use external schema” option and insert the path to the Schematron schema at the related edit field. If the batch will process a large number of files it is also good to select the “Use xinclude for efficient log file creation” option. In this case the log is created as two files. The first one is then the main log file which will include the second file, containing all of the <file> elements for each document, using a xinclude element. This makes it possible to write the complete XML log without the need to keep it in memory during the batch.

After you clicked the “Run batch” button the batch task is executed in a separate process and a XML log file will be created while the batch is running. For each document a file element is added to the log containing the following information if the root node has some child elements:

<file done="true" is_schema="false" path="C:\Users\Documents\xml\xmlschema2006-11-06\msData\additional\ipo_s1.xml" schema_dtd_ref="false" time="06/08/12 16:08:10" valid="false">
  <general>Checked against C:\Users\Documents\xml\Schematron\count_root_child_elements.sch</general>
  <results>
    <result type="error">
      <position col="0" line="0"/>
      <description><![CDATA[3 elements]]></description>
    </result>
  </results>
</file>

And like this if there are no child elements:

<file done="true" is_schema="false" path="C:\Users\Documents\xml\xmlschema2006-11-06\msData\additional\isdefault001.xml" schema_dtd_ref="false" time="06/08/12 16:08:10" valid="false">
  <general>Checked against C:\Users\Documents\xml\Schematron\count_root_child_elements.sch</general> 
  <results>
    <result type="error">
      <position col="0" line="0"/>
      <description><![CDATA[A root element without any child elements]]></description>
    </result>
  </results>
</file>

The log is constantly written while the batch is running. Use the Large File Viewer in XML ValidatorBuddy to open also huge log files after the batch has been completed.

Share
,

Enhanced schema and DTD validation

Beside Schematron validation the XML ValidatorBuddy plugin also includes the popular Xerces parser to do W3C and DTD validation within XMLSpy. But what are the benefits of also having simple access to the Xerces engine in the XML editor? Most of the time people are asking for two things:

  • A second parser to compare validation results and to increase the standard conformance of any self-developed schema.
  • How to get all validation errors at once? In this case XML ValidatorBuddy helps to avoid validating the XML document over and over again. The screenshot above shows a good example where just two minor typos need to be corrected but both of them are reported at once.

 

Share
,

In contrast to many other tools XML ValidatorBuddy supports validation of XML files against W3C schema definitions without an explicit reference in the instance document.

This is done using an XML catalog and an association based on the usage of namespaces in the instance document and the definition of a target namespace in the schema. XML ValidatorBuddy provides a simple command for adding any W3C schema with a target namespace to the internal XML catalog:

add to xml catalog command

Add to XML catalog command

The “Add to Schema catalog for validation” command is part of the File Explorer context menu. Just select a W3C schema file and select the menu item after a right-mouse-click.

Whenever an XML file is validated, any grammar which is available in the XML catalog is also used for validation if a matching namespace usage is found. This way it is no longer necessary to provide a schemaLocation attribute in every XML instance.

Share
, , , ,