Java & XML, 2nd Edition case Node.TEXT_NODE: writer.write(node.getNodeValue(
Java & XML, 2nd Edition case Node.TEXT_NODE: writer.write(node.getNodeValue( )); break; case Node.CDATA_SECTION_NODE: writer.write(” XML constructs. That’s really all there is to it; see this code addition: case Node.COMMENT_NODE: writer.write(indentLevel + ““); writer.write(lineSeparator); break; Moving on to the next DOM node type: the DOM bindings for Java define an interface to handle processing instructions that are within the input XML document, rather obviously called ProcessingInstruction. This is useful, as these instructions do not follow the same markup model as XML elements and attributes, but are still important for applications to know about. In the table of contents XML document, there aren’t any PIs present (although you could easily add some for testing). The PI node in the DOM is a little bit of a break from what you have seen so far: to fit the syntax into the Node interface model, the getNodeValue( ) method returns all data instructions within a PI in one String. This allows quick output of the PI; however, you still need to use getNodeName( ) to get the name of the PI. If you were writing an application that received PIs from an XML document, you might prefer to use the actual ProcessingInstruction interface; although it exposes the same data, the method names (getTarget( ) and getData( )) are more in line with a PI’s format. With this understanding, you can add in the code to print out any PIs in supplied XML documents: case Node.PROCESSING_INSTRUCTION_NODE: writer.write(”" + node.getNodeName( ) + " " + node.getNodeValue( ) + "?>“); writer.write(lineSeparator); break; While the code to deal with PIs is perfectly workable, there is a problem. In the case that handled document nodes, all the serializer did was pull out the document element and recurse. The problem is that this approach ignores any other child nodes of the Document object, such as top-level PIs and any DOCTYPE declarations. Those node types are actually lateral to the document element (root element), and are ignored. Instead of just pulling out the document element, then, the following code serializes all child nodes on the supplied Document object:
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.