1.21k likes | 1.36k Views
E171 Native XML Services in PowerBuilder 9.0. Bio Liong Lim Staff Software Engineer Sybase Asia Development Centre bio-liong.lim@sybase.com. Session Outline. The areas we will be covering. What is DOM ? What is PBDOM ? PBDOM Design Goals. PBDOM Concepts. PBDOM Classes.
E N D
E171 Native XML Services in PowerBuilder 9.0 • Bio Liong Lim • Staff Software Engineer • Sybase Asia Development Centre • bio-liong.lim@sybase.com
Session Outline The areas we will be covering. • What is DOM ? • What is PBDOM ? • PBDOM Design Goals. • PBDOM Concepts. • PBDOM Classes. • The Future of PBDOM.
What is DOM ? What is DOM ?
What is DOM ? DOM. • DOM stands for Document Object Model. • DOM is a W3C standard. • A standard way of representing the contents of an XML document as a tree of interconnected objects. • The next slide demonstrates this.
What is DOM ? Document root child_1 child_2 child_3 Text_1 Text_2 Text_3
What is DOM ? DOM. • In the preceding slide, the elements “root”, “child_1”, etc and the text node “Text_1”, etc are all DOM Nodes. • DOM defines a hierarchy of DOM Object Types starting with the DOM Node.
What is DOM ? The W3C DOM Hierarchy DOCUMENT DOCTYPE NODE ELEMENT ATTRIBUTE PROCESSINGINSTRUCTION ENTITY_REFERENCE NOTATION COMMENT CHARACTERDATA TEXT CDATA
What is DOM ? DOM. • DOM is also a set of APIs for app developers.
What is DOM ? User’s Understanding Of XML and DOM To effectively use PBDOM : • Some knowledge of XML (as defined in the W3C specs). • Basic understanding of the W3C DOM Tree.
Usage Usage [conclude]
Usage User’s Understanding Of XML and DOM • PBDOM uses some fundamental DOM concepts • the DOM node as a base object, • node parentage, node removal, node appending, etc. [conclude]
What is PBDOM ? What is PBDOM ?
What is PBDOM ? High-level DOM Management API. A complete API set to create, read, write and manipulate XML documents. • A large collection of non-visual classes. • Classes are hierarchical in nature and allow for polymorphic usage.
What is PBDOM ? High-level DOM Management API. • PBDOM is a PowerScript language extension and is built on PBNI technology. • It embraces native PowerBuilder datatypes like the boolean, date, datetime, long, etc. • It also uses standard PB facilities like PB arrays. • PS Developers will find the PBDOM classes and their methods natural and easy to use.
What is PBDOM ? High-level DOM Management API. • Efforts were taken to ensure that the PBDOM APIs provide users with great amount of leverage and productivity. • Incurs short learning curve. • Provides indisputable edge over other XML service providers. [conclude]
Design Goals Design Goals
Design Goals What PBDOM aims to achieve : • Instinctive user view of a DOM document... • Flexibility... • Incorporation of PowerScript Facilities... • “Live” Effects... • Building a PBDOM Tree from various input sources.
Design Goals Instinctive user view of a DOM document. • PBDOM portrays an XML document as a collection of interconnected objects (PBDOM_OBJECTs). • The PBDOM APIs indicate what these objects can do as well as what can be done with them.
Design Goals Instinctive user view of a DOM document. • PBDOM classifies different types of XML Nodes into different classes (albeit all deriving from the same base PBDOM_OBJECT class). • Each inherited object has its own specialised methods. • These classes will be covered later in the section on PBDOM classes.
Design Goals Flexibility • The W3C DOM APIs are low-level and are primarily intended for 3-GL developers who are likely to use C++ as their main development tool. • PBDOM aims to present a much higher-level API set.
Design Goals Flexibility • PBDOM allows DOM nodes to be moved around across nodes and across documents easily. Document 1 Document 2 <Parent_Element> <An_Element/> <Child_Element/> </Parent_Element>
Design Goals Flexibility • PBDOM allows DOM nodes to be moved around across nodes and across documents easily. Document 1 Document 2 <Parent_Element> <An_Element/> <Child_Element/> </Parent_Element> element.Detach() <Child_Element/> is now “stand-alone”
Design Goals Flexibility • PBDOM allows DOM nodes to be moved around across nodes and across documents easily. Document 1 Document 2 <Parent_Element/> <An_Element> <Child_Element/> </An_Element> element.SetParentObject() <Child_Element> is now “parent-owned” and “document-owned”
Design Goals Flexibility • PBDOM’s allows convenient re-naming of nodes. <Parent_Element> <Child_Element/> </Parent_Element>
Design Goals Flexibility • PBDOM’s allows convenient re-naming of nodes. <Parent_Element> <Child_Element/> element.SetName(“My_Child_Element”) </Parent_Element>
Design Goals Flexibility • PBDOM’s allows convenient re-naming of nodes. <Parent_Element> <My_Child_Element/> </Parent_Element> <Child_Element> has now been re-named to <My_Child_Element/>
Design Goals Flexibility • PBDOM allows setting and re-setting of the root element of a document. Document 1 <Parent_Element> <My_Element/> <Child_Element/> </Parent_Element> <My_Element> is a “Stand-Alone” PBDOM_ELEMENT.
Design Goals Flexibility • PBDOM allows setting and re-setting of the root element of a document. Document 1 <Parent_Element> <My_Element/> <Child_Element/> </Parent_Element> reference document.SetRootElement(element) We call SetRootElement() on the “Document 1” PBDOM_DOCUMENT.
Design Goals Flexibility • PBDOM allows setting and re-setting of the root element of a document. Document 1 <My_Element/> <My_Element> is now the Root Element of “Document 1”.
Design Goals PowerScript Facilities • PBDOM allows PB developers to use regular PowerScript constructs like arrays to obtain lists of DOM Objects. • The W3C DOM API defines the NodeList and the NamedNodeMap.
Design Goals PowerScript Facilities • Example 1. Let’s say we have a document as shown below and we wish to get all the child elements of <Parent_Element>. Document 1 <Parent_Element> <Child_Element_1/> <Child_Element_2/> <Child_Element_3/> </Parent_Element>
Design Goals PowerScript Facilities • Use PBDOM_ELEMENT class’s GetContent() with an unbounded PBDOM_OBJECT array. Document 1 Unbounded PBDOM_OBJECT array <Parent_Element> <Child_Element_1/> <Child_Element_2/> <Child_Element_3/> </Parent_Element> element::GetContent(ref pbdom_object_array)
Design Goals PowerScript Facilities • The PBDOM_OBJECT array will be filled with references to actual PBDOM_OBJECTs. Document 1 Unbounded PBDOM_OBJECT array <Parent_Element> <Child_Element_1/> PBDOM_OBJECT[1] <Child_Element_2/> PBDOM_OBJECT[2] <Child_Element_3/> PBDOM_OBJECT[3] </Parent_Element> element::GetContent(ref pbdom_object_array)
Design Goals PowerScript Facilities • Example 2. Let’s say we have the following single-element document : Document 1 <Parent_Element/>
Design Goals PowerScript Facilities • We wish to add 3 child elements to <Parent_Element>. We first create an array of 3 child elements : Document 1 Unbounded PBDOM_OBJECT array <Parent_Element/> PBDOM_ELEMENT[1] PBDOM_ELEMENT[2] PBDOM_ELEMENT[3]
Design Goals PowerScript Facilities • We then call on the SetContent() function on <Parent_Element> with reference to the array : Document 1 Unbounded PBDOM_OBJECT array <Parent_Element/> PBDOM_ELEMENT[1] PBDOM_ELEMENT[2] PBDOM_ELEMENT[3] element.SetContent(ref pbdom_object_array)
Design Goals PowerScript Facilities • The 3 child elements are now children of <Parent_Element> : Document 1 Unbounded PBDOM_OBJECT array <Parent_Element> <Child_Element_1/> PBDOM_ELEMENT[1] <Child_Element_2/> PBDOM_ELEMENT[2] <Child_Element_3/> PBDOM_ELEMENT[3] </Parent_Element> element.SetContent(ref pbdom_object_array)
Design Goals “Live” Effects • PBDOM provides a “live” object model where PBDOM_OBJECTs that are returned in an array refer to actual PBDOM_OBJECTs and modifications made on these array items will permanently affect the referenced PBDOM_OBJECTs.
Design Goals “Live” Effects • Let’s use a previous example where we obtained an array of child elements of a parent element : Document 1 Unbounded PBDOM_OBJECT array <Parent_Element> <Child_Element_1/> PBDOM_OBJECT[1] <Child_Element_2/> PBDOM_OBJECT[2] <Child_Element_3/> PBDOM_OBJECT[3] </Parent_Element> element.GetContent(ref pbdom_object_array)
Design Goals “Live” Effects • Now, each item of the array is a reference to an actual PBDOM_OBJECT. Thus, we can call its methods to permanently modify it : Document 1 Unbounded PBDOM_OBJECT array <Parent_Element> <Child_Element_1/> PBDOM_OBJECT[1] <Child_Element_2/> PBDOM_OBJECT[2] <Child_Element_3/> PBDOM_OBJECT[3] </Parent_Element> pbdom_object_array[2].SetName(“My_Child_Element”)
Design Goals “Live” Effects • PBDOM_OBJECT[2] now has its name changed to “My_Child_Element” : Document 1 Unbounded PBDOM_OBJECT array <Parent_Element> <Child_Element_1/> PBDOM_OBJECT[1] <My_Child_Element/> PBDOM_OBJECT[2] <Child_Element_3/> PBDOM_OBJECT[3] </Parent_Element> pbdom_object_array[2].SetName(“My_Child_Element”)
Design Goals Building a PBDOM Tree From Various Input Sources. • Source from which a DOM Tree can be constructed is not limited to a file. • Other input sources should also be available e.g. : • From a string. • From an SQL Query Result Set. • From an existing DOM sub tree. [conclude]
PBDOM Concepts PBDOM Concepts
PBDOM Concepts Base PBDOM_OBJECT class • PBDOM introduces the concept of a base PBDOM_OBJECT. It is a PowerScript class that represents an XML DOM node.
PBDOM Concepts Base PBDOM_OBJECT class • Abstract nature of a PBDOM_OBJECT • The PBDOM_OBJECT class is an “abstract” class. • It is not expected to be directly instantiated and used. • An example is shown next.
PBDOM Concepts Base PBDOM_OBJECT class • Abstract nature of a PBDOM_OBJECT
PBDOM Concepts Base PBDOM_OBJECT class • Abstract nature of a PBDOM_OBJECT • In the preceding example, an exception will be thrown and the exception text will be displayed in a message box :
PBDOM Concepts Stand-Alone, Document-Owned And Parent-Owned PBDOM_OBJECTs • PBDOM presents the concepts of “stand-alone”, “document-owned” and “parent-owned” PBDOM_OBJECTs. • These are states. • Nothing revolutionary but it promotes an Object-Oriented mindset. • It is a by-product of our view of DOM Nodes as objects that can be moved around from node to node and from document to document.
PBDOM Concepts Stand-Alone PBDOM_OBJECTs • Globally and locally created PBDOM_OBJECTs. • Not owned by any document or any parent. • Being stand-alone is just a state. • Whenever any PBDOM_OBJECT is created, it is created as a Stand-Alone Object. • Being stand-alone bears no special intrinsic privileges except that being tied to a parent or a document can prevent a PBDOM_OBJECT from being moved around.
PBDOM Concepts Document-owned PBDOM_OBJECTs • PBDOM_OBJECTs which have been added to a document either directly or indirectly. • A document-owned PBDOM_OBJECT may or may not have any parent.