1 /**
2 * Phoebe DOM Implementation.
3 *
4 * This is a C++ approximation of the W3C DOM model, which follows
5 * fairly closely the specifications in the various .idl files, copies of
6 * which are provided for reference. Most important is this one:
7 *
8 * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/idl-definitions.html
9 *
10 * Authors:
11 * Bob Jamison
12 *
13 * Copyright (C) 2005 Bob Jamison
14 *
15 * This library is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU Lesser General Public
17 * License as published by the Free Software Foundation; either
18 * version 2.1 of the License, or (at your option) any later version.
19 *
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
24 *
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 */
32 #include "lsimpl.h"
34 using namespace org::w3c::dom;
37 bool doTest(char *filename)
38 {
40 ls::DOMImplementationLSImpl domImpl;
41 ls::LSInput input = domImpl.createLSInput();
42 ls::LSParser &parser = domImpl.createLSParser(0, "");
44 DOMString buf;
45 FILE *f = fopen(filename, "rb");
46 if (!f)
47 {
48 printf("Cannot open %s for reading\n", filename);
49 return false;
50 }
51 while (!feof(f))
52 {
53 int ch = fgetc(f);
54 buf.push_back(ch);
55 }
56 fclose(f);
57 input.setStringData(buf);
59 printf("######## PARSE ######################################\n");
60 Document *doc = parser.parse(input);
62 if (!doc)
63 {
64 printf("parsing failed\n");
65 return 0;
66 }
68 //### OUTPUT
69 printf("######## SERIALIZE ##################################\n");
70 ls::LSSerializer &serializer = domImpl.createLSSerializer();
71 ls::LSOutput output = domImpl.createLSOutput();
72 StdWriter writer;
73 output.setCharacterStream(&writer);
74 serializer.write(doc, output);
76 printf("####### Namespace check\n");
77 DOMString svgNamespace = "http://www.w3.org/2000/svg";
78 NodeList list = doc->getElementsByTagNameNS(svgNamespace, "svg");
79 int nodeCount = list.getLength();
80 printf("Nodes:%d\n", nodeCount);
81 for (int i=0; i<nodeCount ; i++)
82 {
83 Node *node = list.item(i);
84 serializer.write(node, output);
85 }
90 delete doc;
91 return 1;
92 }
98 int main(int argc, char **argv)
99 {
100 if (argc!=2)
101 {
102 printf("usage: %s xmlfile\n", argv[0]);
103 return 0;
104 }
105 doTest(argv[1]);
106 return 0;
107 }