-
-
-let load_xml_file = Parser.parse_file
-let load_xml_string = Parser.parse_string
-
-
-let output_escape_string out s =
- for i = 0 to String.length s - 1 do
- match s.[i] with
- | '<' -> output_string out "<"
- | '>' -> output_string out ">"
- | '&' -> output_string out "&"
- | '"' -> output_string out """
- | '\'' -> output_string out "'"
- | c -> output_char out c
- done
-
-let rec print_attributes out tree_ node =
- if node != nil then begin
- output_string out (QName.to_string node.tag);
- output_string out "=\"";
- output_escape_string out node.first_child.data;
- output_char out '"';
- print_attributes out tree_ node.next_sibling
- end
-
-let rec print_xml out tree_ node =
- if node != nil then
- let () =
- if node.tag == QName.text then
- output_escape_string out node.data
- else
- let tag = QName.to_string node.tag in
- output_char out '<';
- output_string out tag;
- let fchild =
- if node.first_child.tag == QName.attribute_map then
- let () =
- print_attributes out tree_ node.first_child.first_child
- in
- node.first_child.next_sibling
- else
- node.first_child
- in
- if fchild == nil then output_string out "/>"
- else begin
- output_char out '>';
- print_xml out tree_ fchild;
- output_string out "</";
- output_string out tag;
- output_char out '>'
- end
- in
- print_xml out tree_ node.next_sibling
-
-
-let root t = t.root
-let first_child _ n = n.first_child
-let next_sibling _ n = n.next_sibling
-let parent _ n = n.parent
-let tag _ n = n.tag
-let data _ n = n.data
-let preorder _ n = n.preorder