{"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"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>XML with Clarion 7 - Clarion<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/clarionsharp.com\/blog\/xml-with-clarion-7\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"XML with Clarion 7 - Clarion\" \/>\n<meta property=\"og:description\" content=\"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; Continue reading XML with Clarion 7 &rarr;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/clarionsharp.com\/blog\/xml-with-clarion-7\/\" \/>\n<meta property=\"og:site_name\" content=\"Clarion\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/softvelocity\/\" \/>\n<meta property=\"article:published_time\" content=\"2010-03-15T18:22:22+00:00\" \/>\n<meta name=\"author\" content=\"dborojovich\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"dborojovich\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/clarionsharp.com\\\/blog\\\/xml-with-clarion-7\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/clarionsharp.com\\\/blog\\\/xml-with-clarion-7\\\/\"},\"author\":{\"name\":\"dborojovich\",\"@id\":\"https:\\\/\\\/clarionsharp.com\\\/blog\\\/#\\\/schema\\\/person\\\/7a40b56b94babbfd735e755567c1c3e6\"},\"headline\":\"XML with Clarion 7\",\"datePublished\":\"2010-03-15T18:22:22+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/clarionsharp.com\\\/blog\\\/xml-with-clarion-7\\\/\"},\"wordCount\":491,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\\\/\\\/clarionsharp.com\\\/blog\\\/#organization\"},\"keywords\":[\"C71\",\"Clarion 7\",\"Report Generator\",\"XML\"],\"articleSection\":[\"Clarion 7\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/clarionsharp.com\\\/blog\\\/xml-with-clarion-7\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/clarionsharp.com\\\/blog\\\/xml-with-clarion-7\\\/\",\"url\":\"https:\\\/\\\/clarionsharp.com\\\/blog\\\/xml-with-clarion-7\\\/\",\"name\":\"XML with Clarion 7 - Clarion\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/clarionsharp.com\\\/blog\\\/#website\"},\"datePublished\":\"2010-03-15T18:22:22+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/clarionsharp.com\\\/blog\\\/xml-with-clarion-7\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/clarionsharp.com\\\/blog\\\/xml-with-clarion-7\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/clarionsharp.com\\\/blog\\\/xml-with-clarion-7\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/clarionsharp.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"XML with Clarion 7\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/clarionsharp.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/clarionsharp.com\\\/blog\\\/\",\"name\":\"Clarion\",\"description\":\"Deliver your software on time, every time\",\"publisher\":{\"@id\":\"https:\\\/\\\/clarionsharp.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/clarionsharp.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/clarionsharp.com\\\/blog\\\/#organization\",\"name\":\"SoftVelocity\",\"url\":\"https:\\\/\\\/clarionsharp.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/clarionsharp.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/clarionsharp.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/svlogonew57.png\",\"contentUrl\":\"https:\\\/\\\/clarionsharp.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/svlogonew57.png\",\"width\":221,\"height\":57,\"caption\":\"SoftVelocity\"},\"image\":{\"@id\":\"https:\\\/\\\/clarionsharp.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/softvelocity\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/SoftVelocity\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/clarionsharp.com\\\/blog\\\/#\\\/schema\\\/person\\\/7a40b56b94babbfd735e755567c1c3e6\",\"name\":\"dborojovich\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/95e22b6b15da9a62474b1992308050bcc353bc3159c64373e292bc006b367b0e?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/95e22b6b15da9a62474b1992308050bcc353bc3159c64373e292bc006b367b0e?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/95e22b6b15da9a62474b1992308050bcc353bc3159c64373e292bc006b367b0e?s=96&d=mm&r=g\",\"caption\":\"dborojovich\"},\"url\":\"https:\\\/\\\/clarionsharp.com\\\/blog\\\/author\\\/dborojovich\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"XML with Clarion 7 - Clarion","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/clarionsharp.com\/blog\/xml-with-clarion-7\/","og_locale":"en_US","og_type":"article","og_title":"XML with Clarion 7 - Clarion","og_description":"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; Continue reading XML with Clarion 7 &rarr;","og_url":"https:\/\/clarionsharp.com\/blog\/xml-with-clarion-7\/","og_site_name":"Clarion","article_publisher":"https:\/\/www.facebook.com\/softvelocity\/","article_published_time":"2010-03-15T18:22:22+00:00","author":"dborojovich","twitter_card":"summary_large_image","twitter_misc":{"Written by":"dborojovich","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/clarionsharp.com\/blog\/xml-with-clarion-7\/#article","isPartOf":{"@id":"https:\/\/clarionsharp.com\/blog\/xml-with-clarion-7\/"},"author":{"name":"dborojovich","@id":"https:\/\/clarionsharp.com\/blog\/#\/schema\/person\/7a40b56b94babbfd735e755567c1c3e6"},"headline":"XML with Clarion 7","datePublished":"2010-03-15T18:22:22+00:00","mainEntityOfPage":{"@id":"https:\/\/clarionsharp.com\/blog\/xml-with-clarion-7\/"},"wordCount":491,"commentCount":2,"publisher":{"@id":"https:\/\/clarionsharp.com\/blog\/#organization"},"keywords":["C71","Clarion 7","Report Generator","XML"],"articleSection":["Clarion 7"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/clarionsharp.com\/blog\/xml-with-clarion-7\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/clarionsharp.com\/blog\/xml-with-clarion-7\/","url":"https:\/\/clarionsharp.com\/blog\/xml-with-clarion-7\/","name":"XML with Clarion 7 - Clarion","isPartOf":{"@id":"https:\/\/clarionsharp.com\/blog\/#website"},"datePublished":"2010-03-15T18:22:22+00:00","breadcrumb":{"@id":"https:\/\/clarionsharp.com\/blog\/xml-with-clarion-7\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/clarionsharp.com\/blog\/xml-with-clarion-7\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/clarionsharp.com\/blog\/xml-with-clarion-7\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/clarionsharp.com\/blog\/"},{"@type":"ListItem","position":2,"name":"XML with Clarion 7"}]},{"@type":"WebSite","@id":"https:\/\/clarionsharp.com\/blog\/#website","url":"https:\/\/clarionsharp.com\/blog\/","name":"Clarion","description":"Deliver your software on time, every time","publisher":{"@id":"https:\/\/clarionsharp.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/clarionsharp.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/clarionsharp.com\/blog\/#organization","name":"SoftVelocity","url":"https:\/\/clarionsharp.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/clarionsharp.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/clarionsharp.com\/blog\/wp-content\/uploads\/2019\/03\/svlogonew57.png","contentUrl":"https:\/\/clarionsharp.com\/blog\/wp-content\/uploads\/2019\/03\/svlogonew57.png","width":221,"height":57,"caption":"SoftVelocity"},"image":{"@id":"https:\/\/clarionsharp.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/softvelocity\/","https:\/\/www.youtube.com\/user\/SoftVelocity"]},{"@type":"Person","@id":"https:\/\/clarionsharp.com\/blog\/#\/schema\/person\/7a40b56b94babbfd735e755567c1c3e6","name":"dborojovich","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/95e22b6b15da9a62474b1992308050bcc353bc3159c64373e292bc006b367b0e?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/95e22b6b15da9a62474b1992308050bcc353bc3159c64373e292bc006b367b0e?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/95e22b6b15da9a62474b1992308050bcc353bc3159c64373e292bc006b367b0e?s=96&d=mm&r=g","caption":"dborojovich"},"url":"https:\/\/clarionsharp.com\/blog\/author\/dborojovich\/"}]}},"_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}]}}