Changeset 35540 in project


Ignore:
Timestamp:
05/09/18 05:39:57 (3 weeks ago)
Author:
svnwiki
Message:

Anonymous wiki edit for IP [140.253.78.165]:

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/4/libxml2

    r35530 r35540  
    5252* [[#text-reader:value]]
    5353* [[#sax:attributes->list]]
    54 * [[#sax:user-parser-file]]
     54* [[#sax:parse-file]]
     55* [[#sax:parse-string]]
    5556* [[#sax:make-handler]]
    5657* [[#sax:free-handler]]
     
    9697
    9798
    98 ==== {{dom:is-element-node?}}
     99==== Example
     100<enscript highlight="scheme">(define (dom-demo)
     101  (define (print-element-names node)
     102    (let loop ((n node))
     103      (when n
     104            (when (dom:is-element-node? n)
     105                  (print "element <" (dom:node-name n) ">")
     106                  (print "@ => " (dom:attributes n)))
     107            (when (dom:is-text-node? n)
     108                  (print "content => " (dom:node-content n)))
     109            (print-element-names (dom:node-children n))
     110            (loop (dom:next-node n)))))
     111  (define ctx (dom:make-parser-context))
     112  (define doc (dom:read-file-with-context ctx "foo.xml" #f 0))
     113  (define root (dom:root-element doc))
     114  (define valid? (dom:is-valid? ctx))
     115  (print "XML is valid?: " valid?)
     116  (print "root: " root)
     117  (print-element-names root)
     118  (dom:free-doc doc)
     119  (dom:cleanup-parser))
     120</enscript>
     121==== Node Types
     122===== {{dom:element-node}}
     123<constant>dom:element-node → 1</constant>
     124DOM element node
     125===== {{dom:attribute-node}}
     126<constant>dom:attribute-node → 2</constant>
     127DOM attribute node
     128===== {{dom:text-node}}
     129<constant>dom:text-node → 3</constant>
     130DOM text node
     131===== {{dom:cdata_section_node}}
     132<constant>dom:cdata_section_node → 4</constant>
     133DOM CData node
     134===== {{dom:entity-ref-node}}
     135<constant>dom:entity-ref-node → 5</constant>
     136DOM Entity reference node
     137===== {{dom:entity-node}}
     138<constant>dom:entity-node → 6</constant>
     139DOM entity node
     140===== {{dom:pi-node}}
     141<constant>dom:pi-node → 7</constant>
     142DOM pi-node
     143===== {{dom:comment-node}}
     144<constant>dom:comment-node → 8</constant>
     145DOM comment node
     146===== {{dom:document-node}}
     147<constant>dom:document-node → 9</constant>
     148DOM document node
     149===== {{dom:document-type-node}}
     150<constant>dom:document-type-node → 10</constant>
     151DOM document type node
     152===== {{dom:document-frag-node}}
     153<constant>dom:document-frag-node → 11</constant>
     154DOM document frag node
     155===== {{dom:notation-node}}
     156<constant>dom:notation-node → 12</constant>
     157DOM notation node
     158===== {{dom:html-document-node}}
     159<constant>dom:html-document-node → 13</constant>
     160DOM HTML document node
     161===== {{dom:dtd-node}}
     162<constant>dom:dtd-node → 14</constant>
     163DOM DTD node
     164===== {{dom:element-decl}}
     165<constant>dom:element-decl → 15</constant>
     166DOM element declaration
     167===== {{dom:attribute-decl}}
     168<constant>dom:attribute-decl → 16</constant>
     169DOM attributte declaration
     170===== {{dom:entity-decl}}
     171<constant>dom:entity-decl → 17</constant>
     172DOM entity declaration
     173===== {{dom:namespace-decl}}
     174<constant>dom:namespace-decl → 18</constant>
     175DOM namespace declaration
     176===== {{dom:xinclude-start}}
     177<constant>dom:xinclude-start → 19</constant>
     178DOM xinclude start declaration
     179===== {{dom:xinclude-end}}
     180<constant>dom:xinclude-end → 20</constant>
     181DOM xinlude end declaration
     182==== API
     183===== {{dom:is-element-node?}}
    99184<procedure>(dom:is-element-node? node) → boolean</procedure>
    100185Checks if specified dom:node is a element node
    101186; {{node}} : A dom:xml-node
    102 ==== {{dom:is-text-node?}}
     187===== {{dom:is-text-node?}}
    103188<procedure>(dom:is-text-node? node) → boolean</procedure>
    104189Checks if specified dom:node is a text node
    105190; {{node}} : A dom:xml-node
    106 ==== {{dom:is-attribute-node?}}
     191===== {{dom:is-attribute-node?}}
    107192<procedure>(dom:is-attribute-node? node) → boolean</procedure>
    108193Checks if specified dom:node is an attribute node
    109194; {{node}} : A dom:xml-node
    110 ==== {{dom:parse-string}}
     195===== {{dom:parse-string}}
    111196<procedure>(dom:parse-string xml-string xml-size URL encoding options) → dom:doc</procedure>
    112197Parse string using the DOM parser API
     
    116201; {{encoding}} : Encoding
    117202; {{options}} : Options
    118 ==== {{dom:parse-string-default}}
     203===== {{dom:parse-string-default}}
    119204<procedure>(dom:parse-string-default str) → dom:doc</procedure>
    120205Parse string using the DOM parser API with default options and encoding
    121206; {{xml-string}} : XML string
    122 ==== {{dom:cleanup-parser}}
     207===== {{dom:cleanup-parser}}
    123208<constant>dom:cleanup-parser → (foreign-lambda void xmlCleanupParser)</constant>
    124209Free the dom:doc
    125 ==== {{dom:parse-file}}
     210===== {{dom:parse-file}}
    126211<procedure>(dom:parse-file filename) → dom:doc</procedure>
    127212Parse a file using the DOM parser API
    128213; {{filename}} : XML file
    129 ==== {{dom:free-doc}}
     214===== {{dom:free-doc}}
    130215<procedure>(dom:free-doc) → unspecified</procedure>
    131216Free the dom:doc
    132217
    133 ==== {{dom:make-parser-context}}
     218===== {{dom:make-parser-context}}
    134219<procedure>(dom:make-parser-context) → dom:parser-context</procedure>
    135220Create a DOM parser context
    136221
    137 ==== {{dom:read-file-with-context}}
    138 <procedure>(dom:read-file-with-context) → dom:doc</procedure>
     222===== {{dom:read-file-with-context}}
     223<procedure>(dom:read-file-with-context context filename encoding options) → dom:doc</procedure>
    139224Parse a XML file using the given DOM parser context
    140 
    141 ==== {{dom:is-valid?}}
    142 <procedure>(dom:is-valid? ctx) → boolean</procedure>
     225; {{context}} : DOM parser context
     226; {{filename}} :
     227; {{encoding}} :
     228; {{options}} :
     229===== {{dom:is-valid?}}
     230<procedure>(dom:is-valid? context) → boolean</procedure>
    143231Checks if the parser context is valid after parsing a file
    144 
    145 ==== {{dom:free-parser-context}}
     232; {{context}} : DOM parser context
     233===== {{dom:free-parser-context}}
    146234<procedure>(dom:free-parser-context) → unspecified</procedure>
    147235Free the dom:parser-context
    148236
    149 ==== {{dom:to-string}}
     237===== {{dom:to-string}}
    150238<procedure>(dom:to-string) → string</procedure>
    151239Convert a dom:node to string including the children nodes
    152240
    153 ==== {{dom:next-node}}
     241===== {{dom:next-node}}
    154242<procedure>(dom:next-node) → dom:node</procedure>
    155243Move to the next dom:node
    156244
    157 ==== {{dom:node-content}}
     245===== {{dom:node-content}}
    158246<procedure>(dom:node-content) → string</procedure>
    159247Returns the contents (text) of the dom:node
    160248
    161 ==== {{dom:node-children}}
     249===== {{dom:node-children}}
    162250<procedure>(dom:node-children) → dom:node</procedure>
    163251Returns the first child node
    164252
    165 ==== {{dom:node-name}}
     253===== {{dom:node-name}}
    166254<procedure>(dom:node-name) → dom:node</procedure>
    167255Returns the name of the dom:node
    168256
    169 ==== {{dom:is-element-name?}}
     257===== {{dom:is-element-name?}}
    170258<procedure>(dom:is-element-name? name dom:node) → boolean</procedure>
    171259Checks if the current name of the  dom:node matches the specified string
    172260; {{name}} : Name (string) to match
    173261; {{dom:node}} :
    174 ==== {{dom:get-attribute}}
     262===== {{dom:get-attribute}}
    175263<procedure>(dom:get-attribute key dom:node) → string</procedure>
    176264Returns the attribute from the specified key
    177265; {{key}} : string
    178266; {{dom:node}} :
    179 ==== {{dom:attributes}}
     267===== {{dom:attributes}}
    180268<procedure>(dom:attributes n) → Association list</procedure>
    181269Returns the complete set of XML attributes for the given node
     
    190278
    191279
    192 ==== {{sax:user-parser-string}}
    193 <procedure>(sax:user-parser-string sax-handler user-data file-name size) → number</procedure>
    194 Parse string using SAX handler
     280==== Example
     281<enscript highlight="scheme">(define (sax-demo)
     282  (define sax
     283    (sax:make-handler
     284      (lambda (localname attribute-list)
     285        (print "[on-start]: "
     286               "localname => "
     287               localname
     288               " "
     289               "@ => "
     290               attribute-list))
     291      (lambda (localname) (print "[on-end]: localname " localname))
     292      (lambda (characters) (print "[on-chars]: characters: " characters))))
     293  (sax:parse-file sax #f "foo.xml")
     294  (sax:free-handler sax))
     295</enscript>
     296===== {{sax:parse-file}}
     297<procedure>(sax:parse-file handler user-data) → number</procedure>
     298Parse a XML file using the SAX handler
     299; {{handler}} : SAX handler
     300; {{user-data}} : SAX parser context
     301===== {{sax:parse-string}}
     302<procedure>(sax:parse-string sax-handler user-data xml-string size) → number</procedure>
     303Parse a XML string using the SAX handler
    195304; {{sax-handler}} :
    196 ; {{user-data}} :
    197 ; {{file-name}} :
    198 ; {{size}} :
    199 ==== {{sax:make-handler}}
     305; {{user-data}} : SAX parser context
     306; {{xml-string}} :
     307; {{size}} : The size of the XML string
     308===== {{sax:make-handler}}
    200309<procedure>(sax:make-handler on-start on-end on-characters) → sax-handler</procedure>
    201310Makes a SAX handler
     
    203312; {{on-end}} : λ called on end of element
    204313; {{on-characters}} : λ called on start of reading characters
    205 ==== {{sax:free-handler}}
     314===== {{sax:free-handler}}
    206315<procedure>(sax:free-handler sax-handler) → unspecified</procedure>
    207316Frees the SAX handler
     
    234343
    235344
    236 ==== {{text-reader:NONE}}
    237 <constant>text-reader:NONE → 0</constant>
    238 
    239 <enscript highlight="scheme">(define text-reader:NONE 0)
     345==== Example
     346<enscript highlight="scheme">(define (text-reader-demo)
     347  (define tr (text-reader:make "foo.xml"))
     348  (define (helper tr)
     349    (when (text-reader:element-node? tr)
     350          (print "<" (text-reader:name tr) ">")
     351          (print "@ => " (text-reader:all-attributes tr)))
     352    (when (text-reader:text-node? tr)
     353          (print "value =>" (text-reader:value tr)))
     354    (if (> (text-reader:read-more tr) 0) (helper tr)))
     355  (helper tr)
     356  (text-reader:free tr))
    240357</enscript>
    241 ==== {{text-reader:element-to-string}}
     358==== Node Types
     359===== {{text-reader:none}}
     360<constant>text-reader:none → 0</constant>
     361Text-Reader none
     362===== {{text-reader:element}}
     363<constant>text-reader:element → 1</constant>
     364Text-Reader element
     365===== {{text-reader:attribute}}
     366<constant>text-reader:attribute → 2</constant>
     367Text-Reader attribute
     368===== {{text-reader:text}}
     369<constant>text-reader:text → 3</constant>
     370Text-Reader text
     371===== {{text-reader:cdata}}
     372<constant>text-reader:cdata → 4</constant>
     373Text-Reader cdata
     374===== {{text-reader:entity-reference}}
     375<constant>text-reader:entity-reference → 5</constant>
     376Text-Reader entity reference
     377===== {{text-reader:entity}}
     378<constant>text-reader:entity → 6</constant>
     379Text-Reader entity
     380===== {{text-reader:processing-instruction}}
     381<constant>text-reader:processing-instruction → 7</constant>
     382Text-Reader processing instruction
     383===== {{text-reader:comment}}
     384<constant>text-reader:comment → 8</constant>
     385Text-Reader comment
     386===== {{text-reader:document}}
     387<constant>text-reader:document → 9</constant>
     388Text-Reader document
     389===== {{text-reader:document-type}}
     390<constant>text-reader:document-type → 10</constant>
     391Text-Reader document type
     392===== {{text-reader:document-fragmenta}}
     393<constant>text-reader:document-fragmenta → 11</constant>
     394Text-Reader document fragments
     395===== {{text-reader:notation}}
     396<constant>text-reader:notation → 12</constant>
     397Text-Reader notation
     398===== {{text-reader:whitespace}}
     399<constant>text-reader:whitespace → 13</constant>
     400Text-Reader whitespace
     401===== {{text-reader:significant-whitespace}}
     402<constant>text-reader:significant-whitespace → 14</constant>
     403Text-Reader signficiant whitespace
     404===== {{text-reader:end-element}}
     405<constant>text-reader:end-element → 15</constant>
     406Text-Reader element end
     407===== {{text-reader:end-entity}}
     408<constant>text-reader:end-entity → 16</constant>
     409Text-Reader entity end
     410===== {{text-reader:xml-declaration}}
     411<constant>text-reader:xml-declaration → 17</constant>
     412Text-Reader XML declaration
     413==== API
     414===== {{text-reader:element-to-string}}
    242415<procedure>(text-reader:element-to-string r) → string</procedure>
    243416Converts a text reader to string including child nodes
    244417; {{text-reader}} :
    245 ==== {{text-reader:end-element-is?}}
     418===== {{text-reader:end-element-is?}}
    246419<procedure>(text-reader:end-element-is? name reader) → boolean</procedure>
    247420Checks if end element is specified name
    248421; {{name}} : Element name (string)
    249422; {{text-reader}} :
    250 ==== {{text-reader:start-element-is?}}
     423===== {{text-reader:start-element-is?}}
    251424<procedure>(text-reader:start-element-is? name reader) → boolean</procedure>
    252425Checks if start element is specified name
    253426; {{name}} : Element name (string)
    254427; {{text-reader}} :
    255 ==== {{text-reader:end-element-node?}}
     428===== {{text-reader:end-element-node?}}
    256429<procedure>(text-reader:end-element-node? reader) → boolean</procedure>
    257430Checks if node is an end element
    258431; {{reader}} :
    259 ==== {{text-reader:text-node?}}
     432===== {{text-reader:text-node?}}
    260433<procedure>(text-reader:text-node? reader) → boolean</procedure>
    261434Checks for text node
    262435; {{reader}} :
    263 ==== {{text-reader:element-node?}}
     436===== {{text-reader:element-node?}}
    264437<procedure>(text-reader:element-node? reader) → boolean</procedure>
    265438Checks if node is an element
    266439; {{reader}} :
    267 ==== {{text-reader:make}}
    268 <procedure>(text-reader:make) → text-reader</procedure>
     440===== {{text-reader:make}}
     441<procedure>(text-reader:make filename) → text-reader</procedure>
    269442Makes a new text-reader
    270 
    271 ==== {{text-reader:read-more}}
     443; {{filename}} :
     444===== {{text-reader:read-more}}
    272445<procedure>(text-reader:read-more text-reader) → unspecified</procedure>
    273446Reads the next node in the text-reader
    274447; {{text-reader}} :
    275 ==== {{text-reader:free}}
     448===== {{text-reader:free}}
    276449<procedure>(text-reader:free text-reader) → unspecified</procedure>
    277450Free the specfied text-reader
    278451; {{text-reader}} :
    279 ==== {{text-reader:node-type}}
     452===== {{text-reader:node-type}}
    280453<procedure>(text-reader:node-type text-reader) → Node type (number)</procedure>
    281454Returns the node type
    282455; {{text-reader}} :
    283 ==== {{text-reader:empty-element?}}
     456===== {{text-reader:empty-element?}}
    284457<procedure>(text-reader:empty-element? text-reader) → boolean</procedure>
    285458Checks if text-reader is empty
    286459; {{text-reader}} :
    287 ==== {{text-reader:move-to-attribute}}
     460===== {{text-reader:move-to-attribute}}
    288461<procedure>(text-reader:move-to-attribute text-reader attribute-name) → number</procedure>
    289462Moves text-reader to the specified attribute
    290463; {{text-reader}} :
    291464; {{attribute-name}} : (string)
    292 ==== {{text-reader:all-attributes}}
     465===== {{text-reader:all-attributes}}
    293466<procedure>(text-reader:all-attributes r) → list</procedure>
    294467Extracts all the attributes from the element. Attributes are placed
    295468into an association list
    296469; {{text-reader}} :
    297 ==== {{text-reader:move-to-next-attribute}}
     470===== {{text-reader:move-to-next-attribute}}
    298471<procedure>(text-reader:move-to-next-attribute text-reader) → number</procedure>
    299472Moves text-reader to the next attribute
    300473; {{text-reader}} :
    301 ==== {{text-reader:move-to-first-attribute}}
     474===== {{text-reader:move-to-first-attribute}}
    302475<procedure>(text-reader:move-to-first-attribute text-reader) → number</procedure>
    303476Moves text-reader to the first attribute
    304477; {{text-reader}} :
    305 ==== {{text-reader:move-to-element}}
     478===== {{text-reader:move-to-element}}
    306479<procedure>(text-reader:move-to-element text-reader) → number</procedure>
    307480Moves text-reader to first element
    308481; {{text-reader}} :
    309 ==== {{text-reader:next}}
     482===== {{text-reader:next}}
    310483<procedure>(text-reader:next text-reader) → number</procedure>
    311484Moves text-reader to next node
    312485; {{text-reader}} :
    313 ==== {{text-reader:next-sibling}}
     486===== {{text-reader:next-sibling}}
    314487<procedure>(text-reader:next-sibling text-reader) → number</procedure>
    315488Moves text-reader to next sibling node
    316489; {{text-reader}} :
    317 ==== {{text-reader:name}}
     490===== {{text-reader:name}}
    318491<procedure>(text-reader:name text-reader) → string</procedure>
    319492Returns the name of the node
    320493; {{text-reader}} :
    321 ==== {{text-reader:value}}
     494===== {{text-reader:value}}
    322495<procedure>(text-reader:value text-reader) → string</procedure>
    323496Returns the value of the node
Note: See TracChangeset for help on using the changeset viewer.