{"id":191,"date":"2012-06-08T20:01:34","date_gmt":"2012-06-08T18:01:34","guid":{"rendered":"http:\/\/xml-tools.com\/xmltribune\/?p=191"},"modified":"2015-11-04T20:28:31","modified_gmt":"2015-11-04T19:28:31","slug":"schematron-count-child-nodes-batch","status":"publish","type":"post","link":"https:\/\/www.xml-buddy.com\/xmltribune\/schematron-count-child-nodes-batch\/","title":{"rendered":"A Schematron sample: Count child nodes in batch mode for many files"},"content":{"rendered":"<p>Schematron is a powerful and useful technology to complement the standard\u00a0W3C Schema and DTD validator in XML <a href=\"http:\/\/www.xml-buddy.com\/ValidatorBuddy.htm\" >ValidatorBuddy<\/a>. However, it is often complicated to configure\u00a0an XML editor\u00a0to apply a Schematron schema to any number of files in an easy to use and simple way.<\/p>\n<p>In this post I want to illustrate how easy it can be to apply a Schematron schema to many files at once in XML <a href=\"http:\/\/www.xml-buddy.com\/ValidatorBuddy.htm\" >ValidatorBuddy<\/a>. I will use the batch-task configuration dialog in the editor\u00a0to setup and run a batch task which can also be used to create standard (W3C\/DTD) batch validator tasks.<\/p>\n<p>The Schematron schema checks and reports how many child elements the root element has:<\/p>\n<pre>&lt;<span style=\"color: #008000;\">?xml<\/span> <span style=\"color: #0000ff;\">version<\/span>=\"1.0\" <span style=\"color: #0000ff;\">encoding<\/span>=\"iso-8859-1\"<span style=\"color: #008000;\">?<\/span>&gt;\r\n&lt;<span style=\"color: #993300;\">iso:schema<\/span> <span style=\"color: #0000ff;\">xmlns<\/span>=\"http:\/\/purl.oclc.org\/dsdl\/schematron\" <span style=\"color: #0000ff;\">xmlns:iso<\/span>=\"http:\/\/purl.oclc.org\/dsdl\/schematron\" <span style=\"color: #0000ff;\">xmlns:sch<\/span>=\"http:\/\/www.ascc.net\/xml\/schematron\" <span style=\"color: #0000ff;\">queryBinding<\/span>=\"xslt2\" <span style=\"color: #0000ff;\">schemaVersion<\/span>=\"ISO19757-3\"&gt;\r\n  &lt;<span style=\"color: #993300;\">iso:title<\/span>&gt;ISO Schematron sample file.&lt;\/<span style=\"color: #993300;\">iso:title<\/span>&gt;\r\n  &lt;<span style=\"color: #993300;\">iso:pattern<\/span> <span style=\"color: #0000ff;\">id<\/span>=\"root.elementcount\"&gt;\r\n    &lt;<span style=\"color: #993300;\">iso:title<\/span>&gt;Count child elements of root&lt;\/<span style=\"color: #993300;\">iso:title<\/span>&gt;\r\n    &lt;<span style=\"color: #993300;\">iso:rule<\/span> <span style=\"color: #0000ff;\">context<\/span>=\"\/*\"&gt;\r\n      &lt;<span style=\"color: #993300;\">iso:report<\/span> <span style=\"color: #0000ff;\">test<\/span>=\"count(*)\"&gt;\r\n        &lt;<span style=\"color: #993300;\">iso:value-of<\/span> <span style=\"color: #0000ff;\">select<\/span>=\"count(*)\"\/&gt; elements\r\n      &lt;\/<span style=\"color: #993300;\">iso:report<\/span>&gt;\r\n      &lt;<span style=\"color: #993300;\">iso:assert<\/span> <span style=\"color: #0000ff;\">test<\/span>=\"count(*) &gt;= 1\"&gt;A root element without any child elements&lt;\/<span style=\"color: #993300;\">iso:assert<\/span>&gt;\r\n    &lt;\/<span style=\"color: #993300;\">iso:rule<\/span>&gt;\r\n  &lt;\/<span style=\"color: #993300;\">iso:pattern<\/span>&gt;\r\n&lt;\/<span style=\"color: #993300;\">iso:schema<\/span>&gt;<\/pre>\n<p>Use the &#8220;Configure and run a batch task&#8230;&#8221; command of the XML <a href=\"http:\/\/www.xml-buddy.com\/ValidatorBuddy.htm\" >ValidatorBuddy<\/a> editor\u00a0to setup the batch. You can find this command in the context menu of the File Explorer tab or in the &#8220;File Explorer&#8221; menu.<\/p>\n<div id=\"attachment_220\" style=\"width: 218px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/xml-buddy.com\/xmltribune\/wp-content\/uploads\/2012\/06\/schematron_batch1.jpg\"><img aria-describedby=\"caption-attachment-220\" loading=\"lazy\" class=\"wp-image-220 size-medium\" title=\"schematron_batch\" src=\"http:\/\/xml-buddy.com\/xmltribune\/wp-content\/uploads\/2012\/06\/schematron_batch1-208x300.jpg\" alt=\"Batch settings for Schematron in dialog\" width=\"208\" height=\"300\" srcset=\"https:\/\/www.xml-buddy.com\/xmltribune\/wp-content\/uploads\/2012\/06\/schematron_batch1-208x300.jpg 208w, https:\/\/www.xml-buddy.com\/xmltribune\/wp-content\/uploads\/2012\/06\/schematron_batch1.jpg 453w\" sizes=\"(max-width: 208px) 100vw, 208px\" \/><\/a><p id=\"caption-attachment-220\" class=\"wp-caption-text\">Schematron batch settings<\/p><\/div>\n<p>Set the starting folder for the batch task in the &#8220;Start folder for batch&#8221; group.<\/p>\n<p>To define a Schematron batch select &#8220;Schematron&#8221; at the &#8220;Parser to use:&#8221; field, check the &#8220;Use external schema&#8221; 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 &#8220;Use xinclude for efficient log file creation&#8221; 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 &lt;file&gt; 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.<\/p>\n<p>After you clicked the &#8220;Run batch&#8221; 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:<\/p>\n<pre><span style=\"color: #993300;\">&lt;file<\/span> <span style=\"color: #0000ff;\">done<\/span>=\"true\" <span style=\"color: #0000ff;\">is_schema<\/span>=\"false\" <span style=\"color: #0000ff;\">path<\/span>=\"C:UsersDocumentsxmlxmlschema2006-11-06msDataadditionalipo_s1.xml\" <span style=\"color: #0000ff;\">schema_dtd_ref<\/span>=\"false\" <span style=\"color: #0000ff;\">time<\/span>=\"06\/08\/12 16:08:10\" <span style=\"color: #0000ff;\">valid<\/span>=\"false\"<span style=\"color: #993300;\">&gt;<\/span>\r\n  <span style=\"color: #993300;\">&lt;general&gt;<\/span>Checked against C:UsersDocumentsxmlSchematroncount_root_child_elements.sch<span style=\"color: #993300;\">&lt;\/general&gt;<\/span>\r\n  <span style=\"color: #993300;\">&lt;results&gt;<\/span>\r\n    <span style=\"color: #993300;\">&lt;result<\/span> <span style=\"color: #0000ff;\">type<\/span>=\"error\"<span style=\"color: #993300;\">&gt;<\/span>\r\n      <span style=\"color: #993300;\">&lt;position<\/span> <span style=\"color: #0000ff;\">col<\/span>=\"0\" <span style=\"color: #0000ff;\">line<\/span>=\"0\"<span style=\"color: #993300;\">\/&gt;<\/span>\r\n      <span style=\"color: #993300;\">&lt;description&gt;<\/span>&lt;![CDATA[3 elements]]&gt;<span style=\"color: #993300;\">&lt;\/description&gt;<\/span>\r\n    <span style=\"color: #993300;\">&lt;\/result&gt;<\/span>\r\n  <span style=\"color: #993300;\">&lt;\/results&gt;<\/span>\r\n<span style=\"color: #993300;\">&lt;\/file&gt;<\/span><\/pre>\n<p>And like this if there are no child elements:<\/p>\n<pre><span style=\"color: #993300;\">&lt;file<\/span> <span style=\"color: #0000ff;\">done<\/span>=\"true\" <span style=\"color: #0000ff;\">is_schema<\/span>=\"false\" <span style=\"color: #0000ff;\">path<\/span>=\"C:UsersDocumentsxmlxmlschema2006-11-06msDataadditionalisdefault001.xml\" <span style=\"color: #0000ff;\">schema_dtd_ref<\/span>=\"false\" <span style=\"color: #0000ff;\">time<\/span>=\"06\/08\/12 16:08:10\" <span style=\"color: #0000ff;\">valid<\/span>=\"false\"<span style=\"color: #993300;\">&gt;<\/span>\r\n  <span style=\"color: #993300;\">&lt;general&gt;<\/span>Checked against C:UsersDocumentsxmlSchematroncount_root_child_elements.sch<span style=\"color: #993300;\">&lt;\/general&gt; <\/span>\r\n  <span style=\"color: #993300;\">&lt;results&gt;<\/span>\r\n    <span style=\"color: #993300;\">&lt;result<\/span> <span style=\"color: #0000ff;\">type<\/span>=\"error\"<span style=\"color: #993300;\">&gt;<\/span>\r\n      <span style=\"color: #993300;\">&lt;position<\/span> <span style=\"color: #0000ff;\">col<\/span>=\"0\" <span style=\"color: #0000ff;\">line<\/span>=\"0\"<span style=\"color: #993300;\">\/&gt;<\/span>\r\n      <span style=\"color: #993300;\">&lt;description&gt;<\/span>&lt;![CDATA[A root element without any child elements]]&gt;<span style=\"color: #993300;\">&lt;\/description&gt;<\/span>\r\n   <span style=\"color: #993300;\"> &lt;\/result&gt;<\/span>\r\n <span style=\"color: #993300;\"> &lt;\/results&gt;<\/span>\r\n<span style=\"color: #993300;\">&lt;\/file&gt;<\/span><\/pre>\n<p>The log is constantly written while the batch is running. Use the Large File Viewer in XML <a href=\"http:\/\/www.xml-buddy.com\/ValidatorBuddy.htm\" >ValidatorBuddy<\/a> to open also huge log files after the batch has been completed.<\/p>\n<p style=\"opacity:0.5;padding:0;margin:0;display:inline;\"><sub><a href=\"#\" onclick=\"window.open('https:\/\/www.janhvizdak.com\/rdr.me.1'); return false;\" target=\"_blank\" style=\"cursor:help;\"><b>&#187;crosslinked&#171;<\/b><\/a><\/sub><\/p>","protected":false},"excerpt":{"rendered":"<p>Schematron is a powerful and useful technology to complement the standard\u00a0W3C Schema and DTD validator in XML ValidatorBuddy. However, it is often complicated to configure\u00a0an XML editor\u00a0to 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&#8230; <a href=\"https:\/\/www.xml-buddy.com\/xmltribune\/schematron-count-child-nodes-batch\/\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[12,1,6],"tags":[15,69],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.xml-buddy.com\/xmltribune\/wp-json\/wp\/v2\/posts\/191"}],"collection":[{"href":"https:\/\/www.xml-buddy.com\/xmltribune\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xml-buddy.com\/xmltribune\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xml-buddy.com\/xmltribune\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xml-buddy.com\/xmltribune\/wp-json\/wp\/v2\/comments?post=191"}],"version-history":[{"count":3,"href":"https:\/\/www.xml-buddy.com\/xmltribune\/wp-json\/wp\/v2\/posts\/191\/revisions"}],"predecessor-version":[{"id":587,"href":"https:\/\/www.xml-buddy.com\/xmltribune\/wp-json\/wp\/v2\/posts\/191\/revisions\/587"}],"wp:attachment":[{"href":"https:\/\/www.xml-buddy.com\/xmltribune\/wp-json\/wp\/v2\/media?parent=191"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xml-buddy.com\/xmltribune\/wp-json\/wp\/v2\/categories?post=191"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xml-buddy.com\/xmltribune\/wp-json\/wp\/v2\/tags?post=191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}