Changeset 2025
- Timestamp:
- 04/15/10 16:33:38 (5 months ago)
- Location:
- trunk/modules/Dom3/source
- Files:
-
- 2 modified
-
read.cl (modified) (2 diffs)
-
xmlcore.cl (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/modules/Dom3/source/read.cl
r2013 r2025 49 49 if (attrs["version"] != "") _x.xmlVersion := attrs["version"], 50 50 if (attrs["encoding"] != "") ( 51 _x.inputEncoding := attrs["encoding"],52 51 _x.xmlEncoding := attrs["encoding"]), 53 52 _x] … … 80 79 Sax/sax(parser), 81 80 d)] 82 /*83 [file2document!(pathFile:string) : Document84 -> let d := Document()85 p := fopen(pathFile,"r")86 in (Sax/sax(p,domStartHandler,domEndHandler,d), d)]87 81 88 89 // @chapter 2 90 // construct a node base XML tree given a raw of string 91 [makeXMLNode(rawtext:string) : XMLNode 92 -> let d := XMLNode(), 93 p := port!(rawtext) 94 in (Sax/sax(p,domStartHandler,domEndHandler,d), 95 d.children[1])] 96 /* parseXMLStr(rawtext), */ 97 // d)] 98 /* 99 // @chapter 2 100 // nodes count in a XML tree 101 [count(n:(XMLNode U XMLDoc)) : integer 102 -> let i := 1 103 in (for sn in n.children (i :+ count(sn)),i)] 104 105 106 107 // @chapter 2 108 // access to named sub node 109 [subNodeOfName(self:XMLNode,nodeName:string) : (XMLNode U {unknown}) 110 -> some(i in self.children | insensitive=(i.tagname,nodeName))] 111 112 // @chapter 2 113 // access to named sub nodes 114 [subNodesOfName(self:Dom/XMLNode,nodeName:string) : set[Dom/XMLNode] 115 -> {i in self.children | insensitive=(i.tagname,nodeName)}] 116 117 // @chapter 2 118 // add named sub nodes 119 [addSubNodeWithName(self:Dom/XMLNode,keyname:string) : Dom/XMLNode 120 -> let node := Dom/XMLNode(tagname = upper(keyname)) in (self.children :add node, node)] 121 */ 82 [file(s:string) : Document 83 -> let f := fopen(s,"r"), res := document!(f) in (fclose(f),res)] -
trunk/modules/Dom3/source/xmlcore.cl
r2018 r2025 80 80 prefix:string, 81 81 localName:string, 82 inputEncoding:string = "UTF-8", // An attribute specifying the encoding used for this document at the time of the parsing83 interfaceEncoding:string = "UTF-8", // encoding used when getting string84 xmlEncoding:string = "UTF-8", // An attribute specifying, as part of the XML declaration, the encoding of this document85 82 xmlStandalone:boolean = false, // An attribute specifying, as part of the XML declaration, whether this document is standalone. This is false when unspecified 86 83 xmlVersion:string = "1.0" // An attribute specifying, as part of the XML declaration, the version number of this document. … … 93 90 doctype:DocumentType, 94 91 implementation:DOMImplementation = DOMImplementation(), 95 documentElement:Element) 92 documentElement:Element, 93 mime:string = "application/xml", 94 interfaceEncoding:string = "UTF-8", // encoding used when getting string 95 xmlEncoding:string = "UTF-8") // An attribute specifying, as part of the XML declaration, the encoding of this document 96 96 97 97 DocumentFragment <: Node() … … 104 104 105 105 [createElement(doc:Document,tagname:string) : Element -> Element(ownerDocument = doc, tagName = tagname)] 106 107 [createElement(elem:Element,tagname:string) : Element -> 108 let e := Element(ownerDocument = elem.ownerDocument, 109 tagName = tagname) 110 in (appendChild(elem,e), 111 e)] 112 106 113 [createDocumentFragment(doc:Document) : DocumentFragment -> DocumentFragment()] 107 114 [createTextNode(doc:Document,_data:string) : Text -> Text(data = _data, ownerDocument = doc)] … … 178 185 newChild] 179 186 187 [appendChild(node:Node,newChilds:list[Node]) : Node -> 188 //[3] appendChild(~S,~S) // node, newChilds, 189 for n in newChilds appendChild(node,n), 190 if (length(newChilds) > 0) last(newChilds) 191 else node] 192 193 180 194 181 195 [hasChildNodes(node:Node) : boolean -> length(node.childNodes) > 0] … … 194 208 [nth(self:Node,key:string) : string 195 209 -> when attrib := some( a in self.attributes | (a.name = key)) in 196 (if (attrib.ownerDocument. inputEncoding != attrib.ownerDocument.interfaceEncoding)197 Iconv/iconv(attrib.value,attrib.ownerDocument.interfaceEncoding,attrib.ownerDocument. inputEncoding)210 (if (attrib.ownerDocument.xmlEncoding != attrib.ownerDocument.interfaceEncoding) 211 Iconv/iconv(attrib.value,attrib.ownerDocument.interfaceEncoding,attrib.ownerDocument.xmlEncoding) 198 212 else attrib.value ) else ""] 199 213 … … 201 215 // setting XML Node attribute 202 216 [nth=(self:Node,key:string,val:string) : void 203 -> if (self.ownerDocument. inputEncoding != self.ownerDocument.interfaceEncoding)204 val := Iconv/iconv(val,self.ownerDocument. inputEncoding,self.ownerDocument.interfaceEncoding),217 -> if (self.ownerDocument.xmlEncoding != self.ownerDocument.interfaceEncoding) 218 val := Iconv/iconv(val,self.ownerDocument.xmlEncoding,self.ownerDocument.interfaceEncoding), 205 219 when attrib := some( a in self.attributes | (a.name = key)) in ( 206 220 attrib.value := val ) 207 221 else self.attributes :add Attr(parentNode = self, ownerDocument = self.ownerDocument, name = key, value = val)] 208 222 223 [nth=(self:Node,key:string,val:integer) : void -> nth=(self,key,string!(val))] 224 [nth=(self:Node,key:string,val:float) : void -> nth=(self,key,string!(val))] 209 225 210 226 … … 235 251 Element <: Node(tagName:string) 236 252 237 [getAttribute(elem:Element,attrname:string) : string -> elem[attrname]] 238 239 [setAttribute(elem:Element,attrname:string,val:string) : void -> elem[attrname] := val] 253 [getAttribute(elem:Element,attrname:string) : string -> 254 if (elem.ownerDocument.interfaceEncoding != elem.ownerDocument.xmlEncoding) 255 Iconv/iconv(elem[attrname],elem.ownerDocument.interfaceEncoding,elem.ownerDocument.xmlEncoding) 256 else elem[attrname]] 257 258 [setAttribute(elem:Element,attrname:string,val:string) : void -> 259 if (elem.ownerDocument.interfaceEncoding != elem.ownerDocument.xmlEncoding) 260 elem[attrname] := Iconv/iconv(val,elem.ownerDocument.xmlEncoding,elem.ownerDocument.interfaceEncoding) 261 else elem[attrname] := val] 262 240 263 [removeAttribute(elem:Element,attrname:string) : void -> when attrib := some( a in elem.attributes | (a.name = attrname)) in delete(elem.attributes,attrib)] 241 264
