Home > Articles

This chapter is from the book

This chapter is from the book

Additional Interfaces

There are nine additional interfaces that we will not examine in low-level detail but will be required for many applications. The first four have to do with actual content:

  • CharacterData The CharacterData interface extends Node. No DOM objects of type CharacterData exist but rather this object represents common methods inherited by other DOM interfaces. The CharacterData interface contains eight methods for setting, getting, inserting, appending, and otherwise manipulating normal character data information.

  • Comment The Comment interface extends CharacterData and represents a comment in an XML document. No additional methods are defined on this interface.

  • Text The Text interface extends CharacterData. The Text interface contains a single method splitText(int offset) that allows the given text node to be split at an offset into two text nodes which may later be recombined with normalize();.

  • CDATASection The CDATASection interface extends Text and allows for blocks of text to be contained within a DOM node that would otherwise be considered markup without the need to escape markup characters. No additional methods are defined in this interface.

The next five interfaces represent other elements in XML.

  • Entity Extends Node. Represents the Entities within an XML document. Depending on validation, these entities may or may not be expanded and the object may (not expanded, non-validating parsers) or may not (expanded) have children. Defines three methods for accessing entity information.

  • Notation Extends Node. Represents the Notation elements of an XML document. Defines two methods for accessing information about a Notation.

  • DocumentType Extends Node. The DocumentType interface is used to gather information about the Document itself and has three methods for accessing Entities, Notations, and the name of the DTD itself.

  • ProcessingInstruction Extends Node. The ProcessingInstruction interface represents processing instruction information. This interface specifies three methods for accessing and manipulating processing instruction information.

  • DocumentFragment Extends Node. Contains no additional methods beyond the Node interface. The DocumentFragment interface is designed to allow users and developers to develop XML documents that are not well formed. A document fragment can be built that represents data at any level in an XML tree. After being inserted back into a Document object, the underlying children are inserted and not the DocumentFragment object itself. For these reasons, DocumentFragments can be thought of as lightweight Documents.

Listing 3.7, DumpXMLOracle.java, uses the Oracle DOM and wraps up all of the DOM Core Level I interfaces into one neat package that displays, in semi human-readable format, any given XML document. The output is shown in Listing 3.8.

Listing 3.7 DumpXMLOracle.java

  1: /*
  2:  * @(#)DumpXMLOracle.java        1.0 99/05/28
  3:  *
  4:  * Copyright (c) 1999 Sams Publishing. All Rights Reserved.
  5:  *
  6:  */
  7: package sams.chp3;
  8:
  9: import java.io.*;
 10: import java.net.*;
 11:
 12: import oracle.xml.parser.XMLParser;
 13:
 14: import org.w3c.dom.*;
 15:
 16: public class DumpXMLOracle
 17: {
 18:     // map the type to a string
 19:     static String mapNodeTypeToString(short nodeType)
 20:     {
 21:         switch(nodeType)
 22:         {
 23:             case org.w3c.dom.Node.ATTRIBUTE_NODE: return "ATTRIBUTE_NODE";
 24:             case org.w3c.dom.Node.CDATA_SECTION_NODE:return "CDATA_SECTION_NODE";
 25:             case org.w3c.dom.Node.COMMENT_NODE: return "COMMENT_NODE";
 26:             case org.w3c.dom.Node.DOCUMENT_FRAGMENT_NODE: return 
"DOCUMENT_FRAGMENT_NODE";
 27:             case org.w3c.dom.Node.DOCUMENT_NODE: return "DOCUMENT_NODE";
 28:             case org.w3c.dom.Node.DOCUMENT_TYPE_NODE: return "DOCUMENT_TYPE_NODE";
 29:             case org.w3c.dom.Node.ELEMENT_NODE: return "ELEMENT_NODE";
 30:             case org.w3c.dom.Node.ENTITY_NODE: return "ENTITY_NODE";
 31:             case org.w3c.dom.Node.ENTITY_REFERENCE_NODE: return 
"ENTITY_REFERENCE_NODE";
 32:             case org.w3c.dom.Node.NOTATION_NODE: return "NOTATION_NODE";
 33:             case org.w3c.dom.Node.PROCESSING_INSTRUCTION_NODE: return 
"PROCESSING_INSTRUCTION_NODE";
 34:             case org.w3c.dom.Node.TEXT_NODE: return "TEXT_NODE";
 35:
 36:         }
 37:         return "Unknown";
 38:     }
 39:
 40:     // Display attribute information
 41:     static void displayAttributeInfo(String prefix, Node node)
 42:     {
 43:         // only elements have attributes
 44:         if (node.getNodeType() != org.w3c.dom.Node.ELEMENT_NODE) return;
 45:
 46:         NamedNodeMap attributes = node.getAttributes();
 47:         if ( null == attributes || attributes.getLength() == 0)
 48:         {
 49:             return;
 50:         }
 51:
 52:         System.out.println(prefix +"has " + attributes.getLength() +              " 
attributes");
 53:         System.out.println(prefix + attributes.toString());
 54:         for (int i = 0; i < attributes.getLength(); i++)
 55:         {
 56:             Node attribute = attributes.item(i);
 57:             System.out.print(prefix+"["+i+"] " + attribute.getNodeName());
 58:             System.out.println(" = " + attribute.getNodeValue());
 59:         }
 60:
 61:     }
 62:
 63:     // Display generalized node properties
 64:     static void displayNodeInfo(String prefix,Node node)
 65:     {
 66:         System.out.println(prefix+ "----------------");
 67:         System.out.println(prefix + "name:"+node.getNodeName());
 68:         System.out.println(prefix + "type:("+node.getNodeType()+ ")" 
+mapNodeTypeToString(node.getNodeType()));
 69:         System.out.println(prefix + "value:"+ node.getNodeValue());
 70:         displayAttributeInfo(prefix,node);
 71:         if (node.getNodeType() != org.w3c.dom.Node.TEXT_NODE)
 72:         {
 73:             NodeList children = node.getChildNodes();
 74:             System.out.println(prefix + "Children("+ children.getLength()+"):");
 75:             if ( children.getLength() > 0)
 76:             {
 77:                 System.out.print(prefix+ "    ");
 78:                 for (int i = 0; i < children.getLength(); i++)
 79:                 {
 80:                     Node child = children.item(i);
 81:                     System.out.print(" ["+i+"] " + child.getNodeName());
 82:                 }
 83:                 System.out.println();
 84:             }
 85:
 86:         }
 87:     }
 88:     // Display Entity Information
 89:     static void displayEntityInfo(String prefix, Entity entity)
 90:     {
 91:         System.out.println(prefix + "Entity information");
 92:         System.out.println(prefix + "     public id:"+ entity.getPublicId());
 93:         System.out.println(prefix + "     system id:"+ entity.getSystemId());
 94:         System.out.println(prefix + "     notation name:"+ entity.getNotationName());
 95:         displayNodeInfo(prefix,entity);
 96:
 97:         NodeList children = entity.getChildNodes();
 98:         if ( children.getLength() == 0)
 99:             System.out.println(prefix + "     Has 0 children");
100:         else
101:             System.out.println(prefix + "     Children(" + children.getLength()+ 
")");
102:
103:         for (int i = 0; i < children.getLength(); i++)
104:         {
105:             Node child = (Entity)children.item(i);
106:             System.out.println("    child(" + i + ")");
107:             displayNodeInfo("        ",child);
108:         }
109:
110:     }
111:     // Display Document information
112:     static void displayDocumentInfo(Document document)
113:     {
114:         DocumentType docTypeInfo = document.getDoctype();
115:         System.out.println(" ");
116:         System.out.println("Document Type Information");
117:         System.out.println("----------------");
118:         System.out.println("name:"+document.getNodeName());
119:         System.out.println("type:("+document.getNodeType()+ ")" 
+mapNodeTypeToString(document.getNodeType()));
120:         System.out.println("value:"+ document.getNodeValue());
121:         System.out.println("    Properties");
122:         System.out.println("    Name Property:"+docTypeInfo.getName());
123:         NamedNodeMap entities = docTypeInfo.getEntities();
124:         System.out.println("    contains " + entities.getLength() + " entities");
125:         NamedNodeMap notations = docTypeInfo.getNotations();
126:         if ( notations != null)
127:             System.out.println("    contains " + notations.getLength() +             
      " notations");
128:         else
129:             System.out.println("    contains (null) notations");
130:
131:         if ( entities != null && entities.getLength() > 0)
132:         {
133:             System.out.println("    Entities");
134:             for (int i = 0; i < entities.getLength(); i++)
135:             {
136:                 //
137:          // Note that in the SUN implementation this works as expected
138:                 // The IBM implementation causes a class cast exception.
139:                 try
140:                 { 
141:                     Entity entity = (Entity)entities.item(i);
142:                     System.out.println("    Entity(" + i + ")");
143:                     displayEntityInfo("        ",entity);
144:                 }
145:                 catch (Exception e) {  System.out.println("exception! "              
         + e); }  ;
146:             }
147:         }
148:
149:         if ( notations != null && notations.getLength() > 0)
150:         {
151:             System.out.println("    Notations");
152:             for (int i = 0; i < notations.getLength(); i++)
153:             {
154:                 Node node = notations.item(i);
155:                 System.out.println("    Notation(" + i + ")");
156:                 displayNodeInfo("        ",node);
157:             }
158:         }
159:
160:
161:     }
162:
163:     // Process all the children of a node.
164:     public static void displayChildren(String prefix,Node parent)
165:     {
166:         NodeList children = parent.getChildNodes();
167:         if ( children == null || children.getLength() == 0) return;
168:         for (int i = 0; i < children.getLength(); i++)
169:         {
170:             try
171:             {
172:                 Node node = children.item(i);
173:                 displayNodeInfo(prefix,node);
174:                 displayChildren(prefix + "    ",node);   
175:             }
176:             catch (Exception e)
177:             {
178:             }

179:         }
180:
181:
182:     }
183:
184:
185:     public static void main (String argv [])
186:     {
187:         if (argv.length != 1)
188:         {
189:
190:             System.err.println( "Usage: java sams.chp3.DumpXMLOracle filename");
191:             System.exit(1);
192:         }
193:
194:         try
195:         {
196:             XMLParser parser = new XMLParser();
197:             FileInputStream inStream =  new FileInputStream(argv[0]);
198:             parser.setErrorStream(System.err);
199:             parser.setValidationMode(true);
200:             parser.showWarnings(true);
201:
202:             parser.parse(inStream);
203:
204:             Document document = parser.getDocument();
205:             System.out.println("Sucessfully created document on " +                  
 argv[0]);
206:
207:             //
208:             // Print relevent info about the document type
209:             //
210:             displayDocumentInfo(document);
211:             displayNodeInfo("",document);
212:
213:             //
214:             // Now walk the document itself displaying data
215:             //
216:             displayChildren("    ",document);
217:         }
218:         catch (Exception e)
219:         {
220:             System.out.println("Unexpected exception reading document!" +e);
221:             System.out.println(e);
222:             System.exit (0);
223:         }
224:
225:
226:     }

Listing 3.8 Abbreviated Output of DumpXMLOracle.java

  1: C:\java sams.chp3.DumpXMLOracle
  2: Sucessfully created document on catalog.xml
  3:
  4: Document Type Information
  5: ----------------
  6: name:#document
  7: type:(9)DOCUMENT_NODE
  8: value:null
  9:     Properties
 10:     Name Property:catalog
 11:     contains 2 entities
 12:     contains (null) notations
 13:     Entities
 14:     Entity(0)
 15:         Entity information
 16:              public id:null
 17:              system id:null
 18:              notation name:null
 19:         ----------------
 20:         name:PublisherInfo
 21:         type:(6)ENTITY_NODE
 22:         value:MCP
 23:         Children(0):
 24:              Has 0 children
 25:     Entity(1)
 26:         Entity information
 27:              public id:null
 28:              system id:null
 29:              notation name:null
 30:         ----------------
 31:         name:AuthorName
 32:         type:(6)ENTITY_NODE
 33:         value:Albert J. Saganich Jr
 34:         Children(0):
 35:              Has 0 children
 36: ----------------
 37: name:#document
 38: type:(9)DOCUMENT_NODE
 39: value:null
 40: Children(4):
 41:      [0] xml [1] #comment [2] catalog [3] catalog
 42:     ----------------
 43:     name:xml
 44:     type:(7)PROCESSING_INSTRUCTION_NODE
 45:     value: version = '1.0'encoding = 'UTF-8'
 46:     Children(0):
 47:     ----------------
 48:     name:#comment
 49:     type:(8)COMMENT_NODE
 50:     value:
 51:
 52:     A Simple catalog of books a bookstore might carry
 53:
 54:     Al Saganich for Macmillan Computer Publishing
 55:
 56:     Children(0):
 57:     ----------------
 58:     name:catalog
 59:     type:(10)DOCUMENT_TYPE_NODE
 60:     value:null
 61:     Children(0):
 62:     ----------------
 63:     name:catalog
 64:     type:(1)ELEMENT_NODE
 65:     value:null
 66:     Children(7):
 67:          [0] #comment [1] catheader [2] entry [3] entry [4] entry [5] entry [6] 
cattrailer
 68:         ----------------
 69:         name:#comment
 70:         type:(8)COMMENT_NODE
 71:         value:
 72:
 73: This is a comment.
 74:
 75: It follows after <catalog> entry
 76:
 77:         Children(0):
 78:         ----------------
 79:         name:catheader
 80:         type:(1)ELEMENT_NODE
 81:         value:null
 82:         Children(1):
 83:              [0] #text
 84:             ----------------
 85:             name:#text
 86:             type:(3)TEXT_NODE
 87:             value:This is the catalog header only one instance of this guy
 88:         ----------------
 89: . . .
 90:         name:entry
 91:         type:(1)ELEMENT_NODE
 92:         value:null
 93:         Children(7):
 94:              [0] title [1] author [2] author [3] publisher [4] price [5] price [6] 
isbn
 95:             ----------------
 96:             name:title
 97:             type:(1)ELEMENT_NODE
 98:             value:null
 99:             Children(1):
100:                  [0] #text
101:                 ----------------
102:                 name:#text
103:                 type:(3)TEXT_NODE
104:                 value:Special Edition:Using XML and Java 2.0
105:             ----------------
106:             name:author
107:             type:(1)ELEMENT_NODE
108:             value:null
109:             Children(1):
110:                  [0] #text
111:                 ----------------
112:                 name:#text
113:                 type:(3)TEXT_NODE
114:                 value:Al Saganich
115:             ----------------
116:             name:author
117:             type:(1)ELEMENT_NODE
118:             value:null
119:             Children(1):
120:                  [0] #text
121:                 ----------------
122:                 name:#text
123:                 type:(3)TEXT_NODE
124:                 value:Mike Daconta
125:             ----------------
126:             name:publisher
127:             type:(1)ELEMENT_NODE
128:             value:null
129:             Children(1):
130:                  [0] #text
131:                 ----------------
132:                 name:#text
133:                 type:(3)TEXT_NODE
134:                 value:Sams Publishing
135:             ----------------
136:             name:price
137:             type:(1)ELEMENT_NODE
138:             value:null
139:             has 2 attributes
140:             [oracle.xml.parser.XMLAttr@29be915b, oracle.xml.parser. XMLAttr@2b06915b]
141:             [0] discount = retail
142:             [1] cur = us
143:             Children(1):
144:                  [0] #text
145:                 ----------------
146:                 name:#text
147:                 type:(3)TEXT_NODE
148:                 value:9.95
149:             ----------------
150:             name:price
151:             type:(1)ELEMENT_NODE
152:             value:null
153:             has 2 attributes
154:             [oracle.xml.parser.XMLAttr@28ae915b, oracle.xml.parser.                  
XMLAttr@2872915b]
155:             [0] discount = wholesale
156:             [1] cur = us
157:             Children(1):
158:                  [0] #text
159:                 ----------------
160:                 name:#text
161:                 type:(3)TEXT_NODE
162:                 value:7.95
163:             ----------------
164:             name:isbn
165:             type:(1)ELEMENT_NODE
166:             value:null
167:             Children(1):
168:                  [0] #text
169:                 ----------------
170:                 name:#text
171:                 type:(3)TEXT_NODE
172:                 value:0101010124
173:         ----------------
174: . . .
175:         name:entry
176:         type:(1)ELEMENT_NODE
177:         value:null
178:         Children(6):
179:              [0] title [1] author [2] publisher [3] price [4] price [5] isbn
180: . . .
181:         ----------------
182:         name:cattrailer
183:         type:(1)ELEMENT_NODE
184:         value:null
185:         Children(1):
186:              [0] #text
187:             ----------------
188:             name:#text
189:             type:(3)TEXT_NODE
190:             value:This is the catalog trailer only one instance of this guy as well

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020