2 Copyright (c) 2005-2006, John Hurst
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
8 1. Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 3. The name of the author may not be used to endorse or promote products
14 derived from this software without specific prior written permission.
16 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 Kumu::XMLElement::XMLElement(const char* name)
41 Kumu::XMLElement::~XMLElement()
43 for ( Elem_i i = m_ChildList.begin(); i != m_ChildList.end(); i++ )
49 Kumu::XMLElement::SetAttr(const char* name, const char* value)
55 m_AttrList.push_back(TmpVal);
60 Kumu::XMLElement::AddChild(const char* name)
62 XMLElement* tmpE = new XMLElement(name);
63 m_ChildList.push_back(tmpE);
69 Kumu::XMLElement::AddChildWithContent(const char* name, const std::string& value)
71 return AddChildWithContent(name, value.c_str());
76 Kumu::XMLElement::AddChildWithContent(const char* name, const char* value)
80 XMLElement* tmpE = new XMLElement(name);
82 m_ChildList.push_back(tmpE);
88 Kumu::XMLElement::AddChildWithPrefixedContent(const char* name, const char* prefix, const char* value)
90 XMLElement* tmpE = new XMLElement(name);
91 tmpE->m_Body = prefix;
92 tmpE->m_Body += value;
93 m_ChildList.push_back(tmpE);
99 Kumu::XMLElement::AddComment(const char* value)
108 Kumu::XMLElement::Render(std::string& outbuf)
110 outbuf = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
111 RenderElement(outbuf, 0);
116 add_spacer(std::string& outbuf, i32_t depth)
124 Kumu::XMLElement::RenderElement(std::string& outbuf, ui32_t depth)
126 add_spacer(outbuf, depth);
132 for ( Attr_i i = m_AttrList.begin(); i != m_AttrList.end(); i++ )
137 outbuf += (*i).value;
141 // body contents and children
142 if ( ! m_ChildList.empty() )
147 if ( m_Body.length() > 0 )
150 for ( Elem_i i = m_ChildList.begin(); i != m_ChildList.end(); i++ )
151 (*i)->RenderElement(outbuf, depth + 1);
153 add_spacer(outbuf, depth);
158 else if ( m_Body.length() > 0 )