{"id":1661,"date":"2022-08-18T09:06:12","date_gmt":"2022-08-18T09:06:12","guid":{"rendered":"https:\/\/blog.amt.in\/?p=1661"},"modified":"2022-08-18T09:06:12","modified_gmt":"2022-08-18T09:06:12","slug":"introduction-to-data-binding","status":"publish","type":"post","link":"https:\/\/blog.amt.in\/index.php\/2022\/08\/18\/introduction-to-data-binding\/","title":{"rendered":"Introduction to Data Binding"},"content":{"rendered":"<p>In\u00c2\u00a0computer programming,\u00c2\u00a0data binding\u00c2\u00a0is a general technique that binds data sources from the provider and consumer together and\u00c2\u00a0synchronizes\u00c2\u00a0them. This is usually done with two data\/information sources with different languages as in\u00c2\u00a0XML data binding\u00c2\u00a0and\u00c2\u00a0UI data binding. In\u00c2\u00a0UI data binding, data and information objects of the same language but different logic function are bound together (e.g.\u00c2\u00a0Java\u00c2\u00a0UI\u00c2\u00a0elements to Java objects).<\/p>\n<p>In a data binding process, each data change is reflected automatically by the elements that are bound to the data. The term data binding is also used in cases where an outer representation of data in an element changes, and the underlying data is automatically updated to reflect this change. As an example, a change in a\u00c2\u00a0<code>TextBox<\/code>\u00c2\u00a0element could modify the underlying data value.<\/p>\n<p>XML data binding\u00c2\u00a0refers to a means of representing information in an\u00c2\u00a0XML\u00c2\u00a0document as a\u00c2\u00a0business object\u00c2\u00a0in computer memory. This allows\u00c2\u00a0applications\u00c2\u00a0to access the data in the XML from the object rather than using the\u00c2\u00a0DOM\u00c2\u00a0or\u00c2\u00a0SAX\u00c2\u00a0to retrieve the data from a direct representation of the XML itself.<\/p>\n<p>An XML data binder accomplishes this by automatically creating a mapping between elements of the\u00c2\u00a0XML schema\u00c2\u00a0of the document we wish to bind and\u00c2\u00a0members\u00c2\u00a0of a\u00c2\u00a0class\u00c2\u00a0to be represented in memory.<\/p>\n<p>When this process is applied to convert an XML document to an object, it is called\u00c2\u00a0unmarshalling. The reverse process, to serialize an object as XML, is called\u00c2\u00a0marshalling.<\/p>\n<p>Approaches to data binding can be distinguished as follows:<\/p>\n<ul>\n<li><b>XML schema based:<\/b>\u00c2\u00a0Based on an existing XML schema, classes that correspond to the schema are generated.<\/li>\n<li><b>Class based:<\/b>\u00c2\u00a0Based on a set of classes to be serialized, a corresponding XML schema is generated.<\/li>\n<li><b>Mapping-based:<\/b>\u00c2\u00a0A mapping description, usually itself an XML document, describes how en existing XML schema maps to a set of classes, and vice versa.<\/li>\n<\/ul>\n<p>Since XML is inherently sequential and objects are (usually) not, XML data binding mappings often have difficulty preserving all the information in an XML document. Specifically, information like\u00c2\u00a0comments, XML entity references, and sibling order may fail to be preserved in the object representation created by the binding application. This is not always the case; sufficiently complex data binders are capable of preserving 100% of the information in an XML document.<\/p>\n<p>Similarly, since objects in computer memory are not inherently sequential, and may include links to other objects (including self-referential links), XML data binding mappings often have difficulty preserving all the information about an object when it is marshalled to XML.<\/p>\n<p>An alternative approach to automatic data binding relies instead on hand-crafted\u00c2\u00a0XPath\u00c2\u00a0expressions that extract the data from XML. This approach has a number of benefits. First, the data binding code only needs proximate knowledge (e.g., topology, tag names, etc.) of the XML tree structure, which developers can determine by looking at the XML data; XML schemas are no longer mandatory. Furthermore, XPath allows the application to bind the relevant data items and filter out everything else, avoiding the unnecessary processing that would be required to completely unmarshall the entire XML document. The drawback of this approach is the lack of automation in implementing the object model and XPath expressions. Instead the application developers have to create these artifacts manually.<\/p>\n<p>One of XML data binding&#8217;s strengths is the ability to\u00c2\u00a0un\/serialize\u00c2\u00a0objects across programs, languages, and platforms. You can dump a time series of structured objects from a datalogger written in\u00c2\u00a0C (programming language)\u00c2\u00a0on an embedded processor, bring it across the network to process in\u00c2\u00a0Perl\u00c2\u00a0and finally visualize in\u00c2\u00a0Octave. The structure and the data remain consistent and coherent throughout the journey, and no custom formats or parsing is required. This is not unique to XML.\u00c2\u00a0YAML, for example, is emerging as a powerful data binding alternative to XML.\u00c2\u00a0JSON\u00c2\u00a0(which can be regarded as a subset of YAML) is often suitable for lightweight or restricted applications.<\/p>\n<p>UI data binding\u00c2\u00a0is a\u00c2\u00a0software design pattern\u00c2\u00a0to simplify development of\u00c2\u00a0GUI\u00c2\u00a0applications. UI\u00c2\u00a0data binding\u00c2\u00a0binds UI elements to an application\u00c2\u00a0domain model. Most frameworks employ the\u00c2\u00a0Observer pattern\u00c2\u00a0as the underlying binding mechanism. To work efficiently, UI data binding has to address\u00c2\u00a0input validation\u00c2\u00a0and data type mapping.<\/p>\n<p>A\u00c2\u00a0bound control\u00c2\u00a0is a\u00c2\u00a0widget\u00c2\u00a0whose value is tied or\u00c2\u00a0bound\u00c2\u00a0to a field in a\u00c2\u00a0recordset\u00c2\u00a0(e.g., a\u00c2\u00a0column\u00c2\u00a0in a\u00c2\u00a0row\u00c2\u00a0of a\u00c2\u00a0table). Changes made to data within the control are automatically saved to the database when the control&#8217;s exit\u00c2\u00a0event triggers.<\/p>\n<p>The above is a brief about Data Binding. Watch this space for more updates on the latest trends in Technology.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In\u00c2\u00a0computer programming,\u00c2\u00a0data binding\u00c2\u00a0is a general<\/p>\n","protected":false},"author":1,"featured_media":1663,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[626,154,7],"tags":[627,156,18],"class_list":["post-1661","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-binding","category-programming-language","category-techtrends","tag-data-binding","tag-programming-language","tag-technology"],"_links":{"self":[{"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/posts\/1661","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/comments?post=1661"}],"version-history":[{"count":1,"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/posts\/1661\/revisions"}],"predecessor-version":[{"id":1662,"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/posts\/1661\/revisions\/1662"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/media\/1663"}],"wp:attachment":[{"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/media?parent=1661"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/categories?post=1661"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/tags?post=1661"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}