#include <XMLStack.h>
Public Types | |
typedef std::basic_string< _E, _Tr, _A> | _XMLStackString |
typedef XMLStackDocument<_E, _Tr, _A> | _XMLStackDocument |
typedef XMLStackNode<_E, _Tr, _A> | _XMLStackNode |
typedef XMLStackElement<_E, _Tr, _A> | _XMLStackElement |
typedef XMLStackText<_E, _Tr, _A> | _XMLStackText |
typedef XMLStackCDATASection< _E, _Tr, _A> | _XMLStackCDATASection |
typedef XMLStackComment<_E, _Tr, _A> | _XMLStackComment |
typedef XMLStackProcessingInstruction< _E, _Tr, _A> | _XMLStackProcessingInstruction |
typedef XMLStackRawXML<_E, _Tr, _A> | _XMLStackRawXML |
Public Methods | |
XMLStackDocument (unsigned long InitialBufferSize=1024) | |
Constructor which takes an optional XML buffer size. More... | |
XMLStackDocument (const _XMLStackDocument &Instance) | |
Copy constructor. | |
~XMLStackDocument () | |
Destructor. | |
void | pop (void) |
Pops the top node off the stack. More... | |
void | popAll (void) |
Repeatedly calls pop() until no more nodes exist on the stack. More... | |
_XMLStackElement& | pushElement (const _XMLStackString &Name) |
Pushes an element node on the stack. More... | |
_XMLStackElement& | pushElement (const _XMLStackString &Name, const _XMLStackString &NamespaceURI) |
Pushes an element node on the stack and declares the passed in namespace. More... | |
_XMLStackText& | pushText (const _XMLStackString &Data) |
Pushes a text node on the stack. More... | |
_XMLStackCDATASection& | pushCDATASection (const _XMLStackString &Data) |
Pushes a CDATA section node on the stack. More... | |
_XMLStackComment& | pushComment (const _XMLStackString &Data) |
Pushes a comment node on the stack. More... | |
_XMLStackProcessingInstruction& | pushProcessingInstruction (const _XMLStackString &Target) |
Pushes a processing instruction node on the stack. More... | |
_XMLStackRawXML& | pushRawXML (const _XMLStackString &PushXML, const _XMLStackString &PopXML) |
Pushes a raw XML node on the stack. More... | |
_XMLStackNode& | top (void) |
Returns the node on top of the stack. More... | |
const _XMLStackNode& | top (void) const |
Returns the node on top of the stack. More... | |
const _XMLStackString& | xml (void) const |
Returns the contents of the XML buffer. More... | |
void | clear (void) |
Clears the stack, erasing all XML and deleting all nodes. More... | |
unsigned long | stackSize (void) const |
Returns the number of nodes currently on the stack. Zero if empty. | |
void | reserveXMLBufferSize (unsigned long Capacity) |
Creates a buffer for the XML at least as large as Capacity. More... | |
_XMLStackDocument& | operator= (const _XMLStackDocument &Instance) |
Makes a copy of the passed in XMLStackDocument instance. | |
Friends | |
class | XMLStackNode< _E, _Tr, _A > |
class | XMLStackElement< _E, _Tr, _A > |
class | XMLStackAttribute< _E, _Tr, _A > |
class | XMLStackProcessingInstruction< _E, _Tr, _A > |
class | XMLStackText< _E, _Tr, _A > |
class | XMLStackCDATASection< _E, _Tr, _A > |
class | XMLStackRawXML< _E, _Tr, _A > |
class | XMLStackComment< _E, _Tr, _A > |
This class creates XML by pushing and popping various node types onto an internal stack. As nodes are pushed and popped, an internal buffer holds the XML created by the nodes.
The XML is created in a std::basic_string class. The classes are written as templates so that they can support either ANSI or Unicode type strings. Two typedefs are been defined for convenience: AXMLStackDocument (for ANSI strings) and WXMLStackDocument (for Unicode).
<?xml version="1.0" encoding="UTF-16"?> <Book Status="BackOrdered"> <Title>Net Etiquette</Title> <PubId>736</PubId> <Price Currency="USD">19.99</Price> <Author> <LastName>White</LastName> <FirstName>Johnson</FirstName> </Author> </Book> WXMLStackDocument Doc; // Unicode version Doc.pushProcessingInstruction(L"xml") = L"version='1.0' encoding='UTF-16'"; Doc.pop(); // pops the processing instruction Doc.pushElement(L"Book"); Doc.top().createAttribute(L"Status") = L"BackOrdered"; Doc.pushElement(L"Title") = L"Net Etiquette"; Doc.pop(); // pops <Title> Doc.pushElement(L"PubId") = 736; Doc.pop(); // pops <PubId> Doc.pushElement(L"Price").createAttribute(L"Currency") = L"USD"; Doc.top().setValue(19.99, 2); // Assign 19.99 to <Price> Doc.pop(); // pops <Price> Doc.pushElement(L"Author"); Doc.pushElement(L"LastName") = L"White"; Doc.pop(); // pops <LastName> Doc.pushElement(L"FirstName").setValue(L"Johnson"); Doc.popAll(); // Pops off all remaining nodes
Here's another example which demostrates the namespace capabilities:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:TS="http://www.time.gov/"> <SOAP-ENV:Header/> <SOAP-ENV:Body> <TS:GetCurrentTimeRequest> <TimeZone>Eastern</TimeZone> </TS:GetCurrentTimeRequest> </SOAP-ENV:Body> </SOAP-ENV:Envelope> AXMLStackDocument Doc; // ANSI version Doc.pushElement("SOAP-ENV:Envelope", "http://schemas.xmlsoap.org/soap/envelope/"); Doc.top().createAttribute("SOAP-ENV:encodingStyle") = "http://schemas.xmlsoap.org/soap/encoding/"; Doc.top().createAttribute("xmlns:TS") = "http://www.time.gov/"; Doc.pushElement("SOAP-ENV:Header"); Doc.pop(); Doc.pushElement("SOAP-ENV:Body"); // Don't pass the namespace URI because it was already declared in an // ancestor element. We only need to place the namespace prefix TS // in front of the node name to place it in the "http://www.time.gov/" // namespace. Doc.pushElement("TS:GetCurrentTimeRequest"); Doc.pushElement("TimeZone") = "Eastern"; Doc.popAll(); // Pops off all remaining nodes
Definition at line 2000 of file XMLStack.h.
|
Definition at line 2008 of file XMLStack.h. |
|
Definition at line 2009 of file XMLStack.h. |
|
Definition at line 2004 of file XMLStack.h. |
|
Definition at line 2006 of file XMLStack.h. Referenced by pushElement(). |
|
Definition at line 2005 of file XMLStack.h. |
|
Definition at line 2010 of file XMLStack.h. Referenced by pushProcessingInstruction(). |
|
Definition at line 2011 of file XMLStack.h. Referenced by pushRawXML(). |
|
Definition at line 2003 of file XMLStack.h. |
|
Definition at line 2007 of file XMLStack.h. Referenced by pushText(). |
|
Constructor which takes an optional XML buffer size.
Definition at line 2019 of file XMLStack.h. |
|
Copy constructor.
Definition at line 2027 of file XMLStack.h. |
|
Destructor.
Definition at line 2033 of file XMLStack.h. |
|
Clears the stack, erasing all XML and deleting all nodes.
Definition at line 2343 of file XMLStack.h. |
|
Makes a copy of the passed in XMLStackDocument instance.
Definition at line 2371 of file XMLStack.h. |
|
Pops the top node off the stack. Any XML that wasn't previously written to the buffer by the node will be written at this time.
Definition at line 2045 of file XMLStack.h. Referenced by popAll(), and XMLStackElement::setValue(). |
|
Repeatedly calls pop() until no more nodes exist on the stack. If no nodes exist on the stack, then this method does nothing. Definition at line 2060 of file XMLStack.h. |
|
Pushes a CDATA section node on the stack. Like text nodes, CDATA sections contain raw data. However, the special characters '<' and '&' do not need to be escaped. CDATA sections can be used to quote or escape blocks of text to keep that text from being interpreted as markup language. The only delimiter that CDATA recognizes is "]]>", which ends the CDATA section. Unfortunately, if this delimiter can possibly appear in your data, you will need to use a XMLStackText node, at least for part of the data.
Definition at line 2193 of file XMLStack.h. |
|
Pushes a comment node on the stack. Comments cannot contain the character sequence "--".
Definition at line 2222 of file XMLStack.h. |
|
Pushes an element node on the stack and declares the passed in namespace. The element name must conform to the rules for valid element names. Only some basic checking is done to make sure the name is valid, and only when the _DEBUG preprocessor symbol is defined. If a NamespaceURI is provided, no checking is performed to see if it was declared in an ancestor element; it will be written out regardless. If you want the element in a namespace but don't want the xmlns declaration again, only prefix the element name with the namespace qualifier (e.g., "NamespaceQualifier:ElementName"). Don't provide the NamespaceURI.
Definition at line 2127 of file XMLStack.h. |
|
Pushes an element node on the stack. The element name must conform to the rules for valid element names. Only some basic checking is done to make sure the name is valid, and only when the _DEBUG preprocessor symbol is defined.
Definition at line 2083 of file XMLStack.h. |
|
Pushes a processing instruction node on the stack. Represents a processing instruction, which XML defines to keep processor-specific information in the text of the document.
Definition at line 2253 of file XMLStack.h. |
|
Pushes a raw XML node on the stack. This node is used when you want to add raw XML to the buffer without any processing performed on it. Other nodes can be pushed on top of this node type (e.g., child nodes).
Definition at line 2287 of file XMLStack.h. |
|
Pushes a text node on the stack. Text nodes contain raw data that is placed in the XML stream. Automatic conversion is performed for the reserved characters '<' and '&'.
Definition at line 2158 of file XMLStack.h. Referenced by XMLStackElement::setValue(). |
|
Creates a buffer for the XML at least as large as Capacity. This is optional and purely for performance. If you have a good idea of the final buffer size, setting this value early on will give better performance. Otherwise, the buffer will grow as needed.
Definition at line 2362 of file XMLStack.h. |
|
Returns the number of nodes currently on the stack. Zero if empty.
Definition at line 2350 of file XMLStack.h. Referenced by top(). |
|
Returns the node on top of the stack.
Definition at line 2321 of file XMLStack.h. |
|
Returns the node on top of the stack.
Definition at line 2308 of file XMLStack.h. |
|
Returns the contents of the XML buffer.
Definition at line 2335 of file XMLStack.h. |
|
Definition at line 2414 of file XMLStack.h. |
|
Definition at line 2417 of file XMLStack.h. |
|
Definition at line 2419 of file XMLStack.h. |
|
Definition at line 2413 of file XMLStack.h. |
|
Definition at line 2412 of file XMLStack.h. |
|
Definition at line 2415 of file XMLStack.h. |
|
Definition at line 2418 of file XMLStack.h. |
|
Definition at line 2416 of file XMLStack.h. |