Description
Inserts a new PBDOM_OBJECT into the current PBDOM_DOCUMENT object.
Syntax
pbdom_document_name.InsertContent(pbdom_object pbdom_object_new, pbdom_object pbdom_object_ref)
Argument |
Description |
---|---|
pbdom_document_name |
The name of a PBDOM_DOCUMENT object |
pbdom_object_new |
The PBDOM_OBJECT to insert |
pbdom_object_ref |
The PBDOM_OBJECT in front of which the new PBDOM_OBJECT will be inserted |
Return value
PBDOM_OBJECT. The modified PBDOM_DOCUMENT object returned as a PBDOM_OBJECT.
Throws
EXCEPTION_INVALID_ARGUMENT -- The input PBDOM_OBJECT to insert is invalid. This can happen if it has not been initialized properly or is a null object reference.
EXCEPTION_USE_OF_UNNAMED_PBDOM_OBJECT -- The input PBDOM_OBJECT to insert has not been given a user-defined name. The same exception is thrown if the reference PBDOM_OBJECT is also not given a user-defined name, unless the reference PBDOM_OBJECT is specifically set to null.
EXCEPTION_PBDOM_OBJECT_INVALID_FOR_USE -- The input PBDOM_OBJECT to insert is not associated with a derived PBDOM_OBJECT. The same exception is thrown if the reference PBDOM_OBJECT is also not associated with a derived PBDOM_OBJECT, unless the reference PBDOM_OBJECT is specifically set to null.
EXCEPTION_PBDOM_OBJECT_ALREADY_HAS_PARENT -- The input PBDOM_OBJECT to insert already as a parent.
EXCEPTION_MULTIPLE_ROOT_ELEMENT -- A PBDOM_ELEMENT is to be inserted, but this document already has a root element.
EXCEPTION_MULTIPLE_DOCTYPE -- A PBDOM_DOCTYPE is to be inserted, but this document already has a DOCTYPE.
EXCEPTION_HIERARCHY_ERROR -- Inserting the PBDOM_OBJECT adversely affects how well-formed the document is.
EXCEPTION_INAPPROPRIATE_USE_OF_PBDOM_OBJECT -- An invalid PBDOM_OBJECT is to be inserted. See AddContent for information on the valid PBDOM_OBJECTs that can be added to a PBDOM_DOCUMENT object.
EXCEPTION_WRONG_PARENT_ERROR -- The reference PBDOM_OBJECT is not a child of this PBDOM_DOCUMENT object.
Examples
A PBDOM_DOCUMENT object is created from an XML string. The PBDOM_ELEMENT pbdom_elem_1 is also created and set as Elem_1. The PBDOM_DOCTYPE pbdom_doctype_1 and the root element pbdom_root_elem are set.
The root element is detached from its parent, which is also the PBDOM_DOCUMENT object itself. This makes it possible to insert pbdom_elem_1 into the document specifically before pbdom_doctype_1.
pbdom_builder pbdom_builder_1 pbdom_document pbdom_doc pbdom_doctype pbdom_doctype_1 pbdom_element pbdom_elem_1 pbdom_element pbdom_elem_root string strXML strXML = "<!DOCTYPE abc [<!-- internal subset -->" strXML += "<!ELEMENT abc (#PCDATA)> " strXML += "<!ELEMENT data&(#PCDATA)> " strXML += "<!ELEMENT inner_data (#PCDATA)>]><abc>" strXML += "Root Element Data<data>ABC Data<inner_data>" strXML += "My Inner Data</inner_data>My Data</data>" strXML += " now with extra& info</abc>" pbdom_builder_1 = Create PBDOM_Builder pbdom_elem_1 = Create PBDOM_Element pbdom_doc = pbdom_builder_1.BuildFromString (strXML) pbdom_elem_1.SetName ("Elem_1") pbdom_doctype_1 = pbdom_doc.GetDocType() pbdom_elem_root = pbdom_doc.GetRootElement() pbdom_elem_root.Detach() pbdom_doc.InsertContent(pbdom_elem_1, pbdom_doctype_1)
The result is the following document, which is not well-formed:
<Elem_1/> <!DOCTYPE abc[<!-- internal subset --> <!ELEMENT abc (#PCDATA)*> <!ELEMENT data (#PCDATA)*> <!ELEMENT inner_data (#PCDATA)*>]>
Usage
When a new PBDOM_OBJECT is inserted into the current PBDOM_DOCUMENT object, the new PBDOM_OBJECT becomes a child node of the current PBDOM_DOCUMENT object. Also, the new PBDOM_OBJECT is to be positioned specifically before another PBDOM_OBJECT, denoted using the second parameter.
If the second PBDOM_OBJECT is specified as null, then the new PBDOM_OBJECT is to be inserted at the end of the list of children of the current PBDOM_DOCUMENT object.
See also