static void storeNode( const XmlNode* node, TiXmlNode* parent) { if (node->isElement()) { XmlElement* e = (XmlElement*)node; TiXmlElement* element = new TiXmlElement( e->getName().c_str() ); //Write out all the attributes for( XmlAttributes::iterator a = e->getAttrs().begin(); a != e->getAttrs().end(); a++ ) { element->SetAttribute(a->first.c_str(), a->second.c_str() ); } //Write out all the child nodes for( XmlNodeList::iterator i = e->getChildren().begin(); i != e->getChildren().end(); i++ ) { storeNode( i->get(), element ); } parent->LinkEndChild( element ); } else if (node->isText()) { XmlText* t = (XmlText*)node; parent->LinkEndChild( new TiXmlText( t->getValue().c_str() ) ); } }
static void storeNode( const XmlNode* node, int depth, std::ostream& out ) { out << std::fixed; // always use fixed notation for( int k=0; k<depth*INDENT; k++ ) out << " "; if ( node->isElement() ) { XmlElement* e = (XmlElement*)node; out << "<" << e->getName(); for( XmlAttributes::iterator a = e->getAttrs().begin(); a != e->getAttrs().end(); a++ ) { out << " " << a->first << "=" << "\"" << a->second << "\""; } out << ">" << std::endl; for( XmlNodeList::iterator i = e->getChildren().begin(); i != e->getChildren().end(); i++ ) { storeNode( i->get(), depth+1, out ); } for( int k=0; k<depth*INDENT; k++ ) out << " "; out << "</" << e->getName() << ">" << std::endl; } else if ( node->isText() ) { XmlText* t = (XmlText*)node; const std::string& text = t->getValue(); if ( text.find_first_of( "<&" ) != std::string::npos ) out << "<![CDATA[" << text << "]]>" << std::endl; else out << text << std::endl; } }
void OutXmlSerializer::process(const char* name, Pointer* ptr, u32 elementSize) { XmlElement* data = new XmlElement; data->setValue("data"); if (name) data->setAttribute("name",name); if ((&m_allocation.allocator()) != (&HeapAllocator::allocator())) { BufferStream temp; temp << hex << setfill('0') << setw(8) << ptr->m_allocator->handle(); data->setAttribute("allocator",temp.string()); } if (m_allocation.alignment() != SerializableAllocation::DefaultAlignment) { BufferStream temp; temp << m_allocation.alignment(); data->setAttribute("align",temp.string()); } if (ptr->m_count > 0) { BufferStream temp; temp << ptr->m_count; data->setAttribute("count",temp.string()); } { BufferStream temp; temp << elementSize; data->setAttribute("size",temp.string()); } { BufferStream temp; Base64::encode(temp,ptr->m_objects,elementSize * ptr->m_count); if (temp.buffer().count() > 0) { XmlText* text = zenic_new XmlText; text->setValue(temp.string()); data->addChild(text); } } ZENIC_ASSERT(m_current); m_current->addChild(data); m_allocation = SerializableAllocation(); }
void OutXmlSerializer::process(const char* name, const char* valueType, BufferStream& value) { XmlElement* variable = zenic_new XmlElement; variable->setValue(valueType); if (name) variable->setAttribute("name",name); XmlText* text = zenic_new XmlText; text->setValue(value.string()); variable->addChild(text); ZENIC_ASSERT(m_current); m_current->addChild(variable); }
void OutXmlSerializer::process(SerializableVersion& version) { if (!m_current) { ZENIC_ASSERT(version.factory()); XmlElement* current = zenic_new XmlElement; current->setValue("object"); { BufferStream temp; temp << m_currentIndex; current->setAttribute("id",temp.string()); } { BufferStream temp; temp << hex << setw(8) << setfill('0') << version.factory()->host(); current->setAttribute("host",temp.string()); } { BufferStream temp; temp << hex << setw(8) << setfill('0') << version.factory()->type(); current->setAttribute("type",temp.string()); } m_current = current; } XmlElement* v = zenic_new XmlElement; v->setValue("version"); XmlText* text = zenic_new XmlText; BufferStream temp; temp << version.version(); text->setValue(temp.string()); v->addChild(text); m_current->addChild(v); }
static void storeNode( XmlNode* node, int depth, std::ostream& out ) { for( int k=0; k<depth*INDENT; k++ ) out << " "; if ( node->isElement() ) { XmlElement* e = (XmlElement*)node; out << "<" << e->getName(); for( XmlAttributes::iterator a = e->getAttrs().begin(); a != e->getAttrs().end(); a++ ) { out << " " << a->first << "=" << "\"" << a->second << "\""; } if ( e->getChildren().empty()) { out << "/>" << std::endl; } else { out << ">" << std::endl; for( XmlNodeList::iterator i = e->getChildren().begin(); i != e->getChildren().end(); i++ ) { storeNode( i->get(), depth+1, out ); } for( int k=0; k<depth*INDENT; k++ ) out << " "; out << "</" << e->getName() << ">" << std::endl; } } else if ( node->isText() ) { XmlText* t = (XmlText*)node; out << t->getValue() << std::endl; } }
void OutXmlSerializer::process(const char* name, Serializable*& object) { XmlElement* reference = new XmlElement; reference->setValue("ref"); if (name) reference->setAttribute("name",name); XmlText* text = new XmlText; if (object) { // insert into list if needed uint i; for (i = 0; i < m_objects.count(); ++i) { if (m_objects[i] == object) break; } if (i == m_objects.count()) m_objects.pushBack(object); BufferStream temp; temp << i; text->setValue(temp.string()); } else text->setValue("null"); reference->addChild(text); ZENIC_ASSERT(m_current); m_current->addChild(reference); }
/** * @brief * Reads the "value" of the element -- another element, or text */ const char *XmlElement::ReadValue(const char *pszData, XmlParsingData *pData, EEncoding nEncoding) { // Read in text and elements in any order const char *pWithWhiteSpace = pszData; pszData = SkipWhiteSpace(pszData, nEncoding); while (pszData && *pszData) { if (*pszData != '<') { // Take what we have, make a text element XmlText *pTextNode = new XmlText(""); if (IsWhiteSpaceCondensed()) pszData = pTextNode->Parse(pszData, pData, nEncoding); else { // Special case: we want to keep the white space so that leading spaces aren't removed pszData = pTextNode->Parse(pWithWhiteSpace, pData, nEncoding); } // Does the text value only contain white spaces? bool bIsBlank = true; { const String sValue = pTextNode->GetValue(); for (uint32 i=0; i<sValue.GetLength(); i++) { if (!IsWhiteSpace(sValue[i])) { bIsBlank = false; break; } } } if (bIsBlank) delete pTextNode; else LinkEndChild(*pTextNode); } else { // We hit a '<' // Have we hit a new element or an end tag? This could also be a XmlText in the "CDATA" style if (StringEqual(pszData, "</", false, nEncoding)) return pszData; else { XmlNode *pNode = Identify(pszData, nEncoding); if (pNode) { pszData = pNode->Parse(pszData, pData, nEncoding); LinkEndChild(*pNode); } else { return nullptr; } } } pWithWhiteSpace = pszData; pszData = SkipWhiteSpace(pszData, nEncoding); } if (!pszData) { // Set error code XmlDocument *pDocument = GetDocument(); if (pDocument) pDocument->SetError(ErrorReadingElementValue, 0, 0, nEncoding); } // Done return pszData; }