Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /smlnj-lib/trunk/Dev/XML/xml-sig.sml
ViewVC logotype

Annotation of /smlnj-lib/trunk/Dev/XML/xml-sig.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3795 - (view) (download)

1 : jhr 3471 (* xml-sig.sml
2 :     *
3 :     * COPYRIGHT (c) 2010 The Fellowship of SML/NJ (http://www.smlnj.org)
4 :     * All rights reserved.
5 :     *)
6 :    
7 :     signature XML =
8 :     sig
9 :    
10 :     type document
11 :     type element
12 :     type comment
13 :     type text
14 :    
15 : jhr 3591 (* elements *)
16 :    
17 : jhr 3471 (* attributes *)
18 :     datatype 'a attr_value
19 :     = NO_ATTR (* attribute not defined *)
20 :     | WRONG_TYPE (* attribute defined, but at a different type *)
21 :     | VALUE of 'a (* attribute value *)
22 :     val getAttr : element * string -> string option
23 :     val getIntAttr : element * string -> int attr_value
24 :     val getRealAttr : element * string -> real attr_value
25 :    
26 : jhr 3591 (* navigation:
27 :     *
28 :     * Nodes are similar to TinyXML's handle type. They are meant to be used
29 :     * with the "//" function to simplify navigation through the tree. For
30 :     * example, consider the document:
31 :     *
32 :     * <Document>
33 :     * <Element attributeA = "valueA">
34 :     * <Child attributeB = "value1" />
35 :     * <Child attributeB = "value2" />
36 :     * </Element>
37 :     * <Document>
38 :     *
39 :     * then one can extract the value of "attributeB" in the 2nd "Child" element
40 :     * as follows:
41 :     *
42 :     * let val root = documentNode doc
43 :     * val elem = root // firstChildElem "Document"
44 :     * // firstChildElem "Element"
45 :     * // nextSiblingElem "Child"
46 :     * in
47 :     * case toElement elem
48 :     * of SOME elem => getAttr(elem, "attributeB")
49 :     * | NONE => raise Fail "cannot find attribute"
50 :     * end
51 :     *)
52 :     type node
53 :     val null : node
54 :     val isNull : node -> bool
55 :     val toElement : node -> element option
56 :     val toText : node -> string option
57 :    
58 :     val // : node * (node -> node) -> node
59 :    
60 :     val firstChild : node -> node
61 :     val firstChildElem : node -> node
62 :     val firstChildName : string -> node -> node
63 :     val child : int -> node -> node
64 :     val childElem : int -> node -> node
65 :     val childName : string -> int -> node -> node
66 :    
67 :     end
68 :    
69 :     (* the XML_DOM interface supports the Document Object Model view of an XML
70 :     * document, incuding editing.
71 :     *)
72 :     signature XML_DOM =
73 :     sig
74 :     include XML
75 :    
76 : jhr 3471 (* element editing *)
77 :     val addAttr : element * string * string -> unit
78 :     val removeAttr : element * string -> unit
79 :    
80 :     end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0