{"id":573,"date":"2010-03-15T14:22:22","date_gmt":"2010-03-15T18:22:22","guid":{"rendered":"https:\/\/clarionsharp.com\/blog\/?p=573"},"modified":"2010-03-15T14:22:22","modified_gmt":"2010-03-15T18:22:22","slug":"xml-with-clarion-7","status":"publish","type":"post","link":"https:\/\/clarionsharp.com\/blog\/xml-with-clarion-7\/","title":{"rendered":"XML with Clarion 7"},"content":{"rendered":"<p><strong>A<\/strong>s with any other file format there are two basic processes that can be done with XML files; <strong>Reading <\/strong>and <strong>Writing<\/strong>.<br \/>\nC7 supports doing both in many ways, without the need of any additional tools.<br \/>\nIn this article we&#8217;ll focus on two different methods, one for writing and one for reading.<\/p>\n<h3>The writing.<\/h3>\n<p>The method discussed for writing is not new to C7 but it was never used in this way.<br \/>\nI&#8217;m talking about the <em>XMLGenerator <\/em>class, the same class as used in the Report Output templates.<br \/>\nMost of the classes used in the Report Output were designed to be used independent of the Report itself.<br \/>\nThe <em>XMLGenerator <\/em>is no exception, and that is why it can be used in a very simple way to create XML files by hand coding the calls to the <em>XMLGenerator <\/em>methods.<\/p>\n<p>The class has methods to create an in memory XML document and once that is done we can flush the<br \/>\ncontent to a file.<\/p>\n<p>The methods are self-documented in the functionality, but lets introduce some code.<\/p>\n<pre><span style=\"color: #0000ff;\">INCLUDE('ABPRXML.INC'),ONCE<\/span><\/pre>\n<pre><span style=\"color: #0000ff;\">XML XMLGenerator<\/span><\/pre>\n<pre><span style=\"color: #0000ff;\">  CODE<\/span><span style=\"color: #0000ff;\">\nXML.Init('breakfast_menu.XML')\nXML.OpenDocument()\nXML.SetEncoding('ISO-8859-1')\nXML.SetRootTag('breakfast_menu')\nXML.AddComment('The root tag is the first tag in the doc')<\/span><span style=\"color: #0000ff;\">\nXML.AddTag('food','')\nXML.AddAttribute('recordNumber','1','food')<\/span><span style=\"color: #0000ff;\">\nXML.CloseDocument()<\/span><\/pre>\n<p>First, as with any class contained within a separate module we need to include the module.<br \/>\nthe class is declared in <strong>ABPRXML.INC<\/strong><br \/>\nAfter that we create a new class instance of type <em>XMLGenerator <\/em>that we conveniently call XML<\/p>\n<p>After that we call the Init method passing the xml file name we want to create.<\/p>\n<p><span style=\"color: #0000ff;\">XML.Init(&#8216;breakfast_menu.XML&#8217;)<\/span><\/p>\n<p>Then we open the document calling the OpenDocument()<br \/>\nAnd start to create the document content.<\/p>\n<p><span style=\"color: #0000ff;\">XML.OpenDocument()<\/span><\/p>\n<p>The class supports many formats for its XML. In this case we use a single root node<br \/>\nthat we set by calling the SetRootTag method.<\/p>\n<p><span style=\"color: #0000ff;\">XML.SetRootTag(&#8216;breakfast_menu&#8217;)<\/span><\/p>\n<p>After that we need to start adding nodes to our tree.<\/p>\n<p><span style=\"color: #0000ff;\">XML.AddTag(&#8216;food&#8217;,&#8221;)<\/span><\/p>\n<p>The Tags can have both attributes and content.<br \/>\nIn this case we add attributes to the last added Tag named &#8216;food&#8217; with the AddAttribute method.<\/p>\n<p><span style=\"color: #0000ff;\">XML.AddAttribute(&#8216;recordNumber&#8217;,&#8217;1&#8242;,&#8217;food&#8217;)<\/span><\/p>\n<p>After adding all our Tags and Attributes we just need to close the document and the content will be written to disk.<\/p>\n<p><span style=\"color: #0000ff;\">XML.CloseDocument()<\/span><\/p>\n<p>Some of the methods used to add content are:<\/p>\n<pre style=\"text-align: justify;\"><span style=\"color: #0000ff;\">SetRootTag\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 PROCEDURE(STRING pRootTag)\nAddComment\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0PROCEDURE(STRING pComment)\nAddTag\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 PROCEDURE(STRING pName,STRING pValue,BYTE pIsCData=0,&lt;STRING pParent&gt;)\nSetTagValue\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 PROCEDURE(STRING pTagName,STRING pValue,BYTE pIsCData=0)\nAddAttribute\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 PROCEDURE(STRING pName,STRING pValue,STRING pTagName)<\/span><\/pre>\n<p>Some of the methods to modify properties of the XML document are:<\/p>\n<pre><span style=\"color: #0000ff;\">AddXMLHeaderAttribute\u00a0\u00a0 PROCEDURE(STRING pName,STRING pValue)\nSetEncoding\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 PROCEDURE(STRING pEncoding)\nSetXSL\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 PROCEDURE(STRING pXSLFileName)\nSetUseCRLF\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 PROCEDURE(BYTE pTrue=1)<\/span><\/pre>\n<p>As you can see, you can create any type of XML document, writing just a little code.<br \/>\nYou don&#8217;t have to worry about the formatting or strings or opening closing Tags, or anything, just call<br \/>\nthe methods and the class will create the document for you.<\/p>\n<p>Just remember that the physical file does not exist until you close the document.<\/p>\n<p>Attached in this document is the full example to generate the XML file.<\/p>\n<p>In the next Part 2 of this article we will be discussing about reading this document using Clarion 7<\/p>\n<p>NOTE: This class is part of the Report output Generator to XML and is included in C7 EE package and can be added to C7 PE<\/p>\n<p><a href=\"https:\/\/clarionsharp.com\/blog\/wp-content\/uploads\/2010\/03\/part1_xmlgenerator.zip\">part1_xmlgenerator<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>As with any other file format there are two basic processes that can be done with XML files; Reading and Writing. C7 supports doing both in many ways, without the need of any additional tools. In this article we&#8217;ll focus on two different methods, one for writing and one for reading. The writing. The method &hellip; <a href=\"https:\/\/clarionsharp.com\/blog\/xml-with-clarion-7\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">XML with Clarion 7<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[19,34,28,30],"class_list":["post-573","post","type-post","status-publish","format-standard","hentry","category-clarion-7","tag-c71","tag-clarion-7","tag-report-generator","tag-xml"],"_links":{"self":[{"href":"https:\/\/clarionsharp.com\/blog\/wp-json\/wp\/v2\/posts\/573","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/clarionsharp.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/clarionsharp.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/clarionsharp.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/clarionsharp.com\/blog\/wp-json\/wp\/v2\/comments?post=573"}],"version-history":[{"count":0,"href":"https:\/\/clarionsharp.com\/blog\/wp-json\/wp\/v2\/posts\/573\/revisions"}],"wp:attachment":[{"href":"https:\/\/clarionsharp.com\/blog\/wp-json\/wp\/v2\/media?parent=573"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/clarionsharp.com\/blog\/wp-json\/wp\/v2\/categories?post=573"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/clarionsharp.com\/blog\/wp-json\/wp\/v2\/tags?post=573"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}