2 * Copyright 2006 The Android Open Source Project
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef SkXMLWriter_DEFINED
9 #define SkXMLWriter_DEFINED
11 #include "SkTDArray.h"
20 SkXMLWriter(bool doEscapeMarkup = true);
21 virtual ~SkXMLWriter();
23 void addS32Attribute(const char name[], int32_t value);
24 void addAttribute(const char name[], const char value[]);
25 void addAttributeLen(const char name[], const char value[], size_t length);
26 void addHexAttribute(const char name[], uint32_t value, int minDigits = 0);
27 void addScalarAttribute(const char name[], SkScalar value);
28 void addText(const char text[], size_t length);
29 void endElement() { this->onEndElement(); }
30 void startElement(const char elem[]);
31 void startElementLen(const char elem[], size_t length);
32 void writeDOM(const SkDOM&, const SkDOM::Node*, bool skipRoot);
34 virtual void writeHeader();
37 virtual void onStartElementLen(const char elem[], size_t length) = 0;
38 virtual void onAddAttributeLen(const char name[], const char value[], size_t length) = 0;
39 virtual void onAddText(const char text[], size_t length) = 0;
40 virtual void onEndElement() = 0;
43 Elem(const char name[], size_t len)
52 void doEnd(Elem* elem);
53 bool doStart(const char name[], size_t length);
55 const char* getHeader();
56 SkTDArray<Elem*> fElems;
61 SkXMLWriter& operator=(const SkXMLWriter&);
64 class SkXMLStreamWriter : public SkXMLWriter {
66 SkXMLStreamWriter(SkWStream*);
67 virtual ~SkXMLStreamWriter();
68 virtual void writeHeader();
69 SkDEBUGCODE(static void UnitTest();)
72 void onStartElementLen(const char elem[], size_t length) SK_OVERRIDE;
73 void onEndElement() SK_OVERRIDE;
74 void onAddAttributeLen(const char name[], const char value[], size_t length) SK_OVERRIDE;
75 void onAddText(const char text[], size_t length) SK_OVERRIDE;
81 class SkXMLParserWriter : public SkXMLWriter {
83 SkXMLParserWriter(SkXMLParser*);
84 virtual ~SkXMLParserWriter();
86 virtual void onStartElementLen(const char elem[], size_t length);
87 virtual void onEndElement();
88 virtual void onAddAttributeLen(const char name[], const char value[], size_t length);
89 virtual void onAddText(const char text[], size_t length) SK_OVERRIDE;