Learning materials for xml parsing and generation:
-------------------------- ------------------------------------------------
Dom and SAX parsing methods are built-in in jdk, and there is no need to import third-party jar packages.
The SAX parsed characters(char[] ch, int start, int length) method will trigger this event as long as there is content between the label and the next label including line breaks\n or spaces. If If the two tags are right next to each other, they will not be triggered if there is no content.
Global variables need to be set to save the obtained values.
In the startElement(String uri, String localName, String qName,Attributes attributes) method, you can get the attribute value of the label that triggered the method
characters(char[] ch, int start, int length ) method to obtain the content of the tag body
endElement(String uri, String localName, String qName) method can encapsulate the content obtained from the previous two methods into an object
The core of DOM parsing only needs to obtain the Document object (dom object), and then perform various operations on the node. Note that the text content in the tag body is regarded as the child node of the tag.
---------------------
SAX generates XML files. This is different from the class used for SAX parsing. Same, the SAXTransformerFactory class is used.
DOM generates XML, and the DocumentBuilderFactory class used in DOM parsing is also used. It should be noted that the document object is used to generate a root node Element, and then the same Elements are connected behind the root node, and finally the root node Element is connected to the document object.
The above is the detailed content of Learning materials for xml parsing and generation. For more information, please follow other related articles on the PHP Chinese website!