Giter VIP home page Giter VIP logo

esax_parser's Introduction

XML SAX parser

API

 Function: file(Filename, Options) -> Result

 Function: stream(Stream, Options) -> Result

 Input:    Filename = string()

           Stream = binary()

           Options = [{OptTag, EventFun()}]

           OptTag = event_fun

           EventFun(Event) -> Result1
                        This function is called for every event sent by the parser. 

 Output:   Result = {endChunk, rest, Rest()} | ok

           Rest() = binary()                            
           Event =
                             startDocument            
                                              Receive notification of the beginning of a document. 
                                              The SAX parser will send this event only once 
                                              after xml prolog. 

                             endChunk
                                              Receive notification of the end of a document. 
                                              The SAX parser will send this event only once, 
                                              and it will be the last event during the parse.

                            {startElement, Name, Attributes}
                                    Name = binary()
                                    Attributes = list()
                                              Receive notification of the beginning of an element. 
                                              The Parser will send this event at the 
                                              beginning of every element in the XML document.                

                            {endElement, Name, Attributes}
                                    Name = binary()
                                    Attributes = list()
                                              Receive notification of the end of an element. 
                                              The SAX parser will send this event 
                                              at the end of every element in the XML document.
                
                            {characters, Content}
                                    Content = binary()
                                              Receive notification of character data.

                            {comment, Comment}
                                    Comment = binary()
                                              Report an XML comment anywhere in the document.

                            {cdata, Cdata}
                                    Cdata = binary()
                                             Report an XML CDATA anywhere in the document.

Example

Chunk of xml file test.xml contain next content

 <?xml version="1.0" encoding="utf-8"?>
    <aw:Address aw:Type="Shipping"> <!-- Comment -->
      <aw:Name>Ellen Mills</aw:Name>
      <aw:Street>123 Maple Street</aw:Street>
      <aw:City>Mill Valley</aw:City>
    </aw:Address>
    <aw:Phone>38099

Run parsing

esax_parser_decoder:file("test.xml", [{event_fun, fun (E) -> io:format("pn", [E]), ok end}]).

Output after parsing

 startDocument
 {startElement,<<"aw:Address">>,[{<<"aw:Type">>,<<"Shipping">>}]}
 {comment,<<"Comment">>} 
 {startElement,<<"aw:Name">>,[]}
 {characters,<<"Ellen Mills">>}
 {endElement,<<"aw:Name">>,[]}
 {startElement,<<"aw:Street">>,[]}
 {characters,<<"123 Maple Street">>}
 {endElement,<<"aw:Street">>,[]}
 {startElement,<<"aw:City">>,[]}
 {characters,<<"Mill Valley">>}
 {endElement,<<"aw:City">>,[]}
 {endElement,<<"aw:Address">>,[]}
 {endChunk,rest,<<"<aw:Phone>38099">>}

esax_parser's People

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.