1 /******************************************************************************
2 * Copyright (c) 2000-2014 Ericsson Telecom AB
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 ******************************************************************************/
11 external function FromMemory(in octetstring data) return integer;
13 //not supported by XmlReaderWrap
14 //external function FromFile(in charstring filename) return integer;
16 external function Cleanup();
18 // return 1 on success, 0 if no more nodes, -1 on error
19 external function XmlRead() return integer;
20 // Gotcha! Can't call it "Read" due to macros in XmlReader.hh
22 type enumerated xmlReaderTypes // copy-paste from libxml2/xmlreader.h
24 XML_READER_TYPE_NONE (0),
25 XML_READER_TYPE_ELEMENT (1),
26 XML_READER_TYPE_ATTRIBUTE (2),
27 XML_READER_TYPE_TEXT (3),
28 XML_READER_TYPE_CDATA (4),
29 XML_READER_TYPE_ENTITY_REFERENCE (5),
30 XML_READER_TYPE_ENTITY (6),
31 XML_READER_TYPE_PROCESSING_INSTRUCTION (7),
32 XML_READER_TYPE_COMMENT (8),
33 XML_READER_TYPE_DOCUMENT (9),
34 XML_READER_TYPE_DOCUMENT_TYPE (10),
35 XML_READER_TYPE_DOCUMENT_FRAGMENT (11),
36 XML_READER_TYPE_NOTATION (12),
37 XML_READER_TYPE_WHITESPACE (13),
38 XML_READER_TYPE_SIGNIFICANT_WHITESPACE (14),
39 XML_READER_TYPE_END_ELEMENT (15),
40 XML_READER_TYPE_END_ENTITY (16),
41 XML_READER_TYPE_XML_DECLARATION (17)
44 external function NodeType() return xmlReaderTypes;
46 external function Name() return charstring;
48 external function Value() return charstring;
50 external function NsUri() return charstring;
52 external function Depth() return integer;
54 external function FirstAttribute() return integer;
55 // ^^-- same problem as Read --VV
56 external function NextAttribute() return integer;
58 /* * * * * * * * * * * * * * * * */
61 xmlReaderTypes node_type,
63 universal charstring node_name,
64 universal charstring node_value,
65 universal charstring ns_uri
68 type record of XmlNode Nodes;
70 type enumerated Ignore_ws { no, ignore_ws }
71 type enumerated Ignore_txt{ no, ignore_text }
73 function gather(in octetstring data, in Ignore_ws ws := no, in Ignore_txt txt := no) return Nodes
76 var integer numnodes := 0;
78 ret := FromMemory(data);
79 // TODO check return value
80 for (ret := XmlRead(); ret > 0; ret := XmlRead()) {
81 var xmlReaderTypes t := NodeType();
82 if ((ws != no and ((t == XML_READER_TYPE_WHITESPACE) or (t == XML_READER_TYPE_SIGNIFICANT_WHITESPACE)))
83 or (txt!= no and (t == XML_READER_TYPE_TEXT))) {
84 //log("skipped a ", t);
87 var XmlNode this_node;
88 this_node.node_type := t;
89 this_node.depth := Depth();
90 this_node.node_name := oct2unichar(char2oct(Name()));
91 this_node.node_value:= oct2unichar(char2oct(Value()));
92 this_node.ns_uri := oct2unichar(char2oct(NsUri()));
94 nodes[numnodes] := this_node;
95 numnodes := numnodes + 1;
97 if (t == XML_READER_TYPE_ELEMENT) {
98 for (ret := FirstAttribute(); ret > 0; ret := NextAttribute()) {
99 var XmlNode this_attribute := {
100 node_type := NodeType(), // usually XML_READER_TYPE_ATTRIBUTE,
102 node_name := oct2unichar(char2oct(Name())),
103 node_value := oct2unichar(char2oct(Value())),
104 ns_uri := oct2unichar(char2oct(NsUri()))
107 nodes[numnodes] := this_attribute;
108 numnodes := numnodes + 1;