3 * Copyright 2006 The Android Open Source Project
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
10 #include "SkXMLParser.h"
12 #include "SkTemplates.h"
15 static void walk_elem(SkXMLParser* parser, const TiXmlElement* elem)
17 //printf("walk_elem(%s) ", elem->Value());
19 parser->startElement(elem->Value());
21 const TiXmlAttribute* attr = elem->FirstAttribute();
24 //printf("walk_elem_attr(%s=\"%s\") ", attr->Name(), attr->Value());
26 parser->addAttribute(attr->Name(), attr->Value());
31 const TiXmlNode* node = elem->FirstChild();
34 if (node->ToElement())
35 walk_elem(parser, node->ToElement());
36 else if (node->ToText())
37 parser->text(node->Value(), strlen(node->Value()));
38 node = node->NextSibling();
41 parser->endElement(elem->Value());
44 static bool load_buf(SkXMLParser* parser, const char buf[])
51 printf("tinyxml error: <%s> row[%d] col[%d]\n", doc.ErrorDesc(), doc.ErrorRow(), doc.ErrorCol());
55 walk_elem(parser, doc.RootElement());
59 bool SkXMLParser::parse(SkStream& stream)
61 size_t size = stream.getLength();
63 SkAutoMalloc buffer(size + 1);
64 char* buf = (char*)buffer.get();
66 stream.read(buf, size);
69 return load_buf(this, buf);
72 bool SkXMLParser::parse(const char doc[], size_t len)
74 SkAutoMalloc buffer(len + 1);
75 char* buf = (char*)buffer.get();
77 memcpy(buf, doc, len);
80 return load_buf(this, buf);
83 void SkXMLParser::GetNativeErrorString(int error, SkString* str)
86 str->set("GetNativeErrorString not implemented for TinyXml");