const char* TiXmlElement::ReadValue( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ) { TiXmlDocument* document = GetDocument(); // Read in text and elements in any order. const char* pWithWhiteSpace = p; p = SkipWhiteSpace( p, encoding ); while ( p && *p ) { if ( *p != '<' ) { // Take what we have, make a text element. TiXmlText* textNode = new TiXmlText( "" ); if ( !textNode ) { if ( document ) document->SetError( TIXML_ERROR_OUT_OF_MEMORY, nullptr, nullptr, encoding ); return nullptr; } if ( IsWhiteSpaceCondensed() ) { p = textNode->Parse( p, data, encoding ); } else { // Special case: we want to keep the white space // so that leading spaces aren't removed. p = textNode->Parse( pWithWhiteSpace, data, encoding ); } if ( !textNode->Blank() ) LinkEndChild( textNode ); else delete textNode; } else { // We hit a '<' // Have we hit a new element or an end tag? This could also be // a TiXmlText in the "CDATA" style. if ( StringEqual( p, "</", false, encoding ) ) { return p; } else { TiXmlNode* node = Identify( p, encoding ); if ( node ) { p = node->Parse( p, data, encoding ); LinkEndChild( node ); } else { return nullptr; } } } pWithWhiteSpace = p; p = SkipWhiteSpace( p, encoding ); } if ( !p ) { if ( document ) document->SetError( TIXML_ERROR_READING_ELEMENT_VALUE, nullptr, nullptr, encoding ); } return p; }
/** * @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; }