SAX (Simple API for XML XML-oriented easy APIs) is also a program interface.
The DOM can be parsed randomly, first loading the XML document into memory, and then accessing the DOM tree in memory in random ways. Sax is parsed sequentially, no need to load the entire XML into memory, once each element, we have no way to access him, so sax occupies less memory, more efficient. Parsing is usually done using sax parsing instead of DOM.
Sax is parsed in the form of callbacks. SAX uses the Observer pattern (similar to events in the GUI). A sax interface is called an event-driven interface.
public class SaxTest1
{
public static void Main (string[] args) throws Parserconfigurationexception, Saxexception, IOException
{
Get a parse factory instance
SAXParserFactory factory = Saxparserfactory.newinstance ();
Get a SAX parser
SAXParser parser = Factory.newsaxparser ();
To parse
Parser.parse (New File ("Student.xml"), New Myhander ());
XML Schema Summary
Simple elements: Refers to only text content, no child elements, and no attributes.
Format: <xs:element name= "XX" type= "xs:string"/>
<xs:element name= "Age" type= "xs:string" >
Properties: All attributes of an element are defined as simple types, and only complex elements can have properties.
Format <xs:attribute name= "xx" type= "yyy"/>
All attributes are optional by default and can be explicitly indicated by the USE keyword as optional or necessary.
<xs:attribute name= "lang" type= "xs:string" use= "optional"/>
We can use default or fixed as a simple type (simple element, attribute)
Specify a default value or a fixed value.
<xs:element name= "Color" type= "xs:string" default= "Red"/>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.