Logo Search packages:      
Sourcecode: rarian version File versions

const char * TiXmlDocument::Parse ( const char *  p,
TiXmlParsingData *  data = 0,
TiXmlEncoding  encoding = TIXML_DEFAULT_ENCODING 
) [virtual]

Parse the given null terminated block of xml data. Passing in an encoding to this method (either TIXML_ENCODING_LEGACY or TIXML_ENCODING_UTF8 will force TinyXml to use that encoding, regardless of what TinyXml might otherwise try to detect.

Implements TiXmlBase.

Definition at line 689 of file tinyxmlparser.cpp.

References ClearError(), TiXmlDeclaration::Encoding(), TiXmlNode::LinkEndChild(), TiXmlBase::Parse(), and TiXmlNode::ToDeclaration().

Referenced by LoadFile().

{
      ClearError();

      // Parse away, at the document level. Since a document
      // contains nothing but other tags, most of what happens
      // here is skipping white space.
      if ( !p || !*p )
      {
            SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN );
            return 0;
      }

      // Note that, for a document, this needs to come
      // before the while space skip, so that parsing
      // starts from the pointer we are given.
      location.Clear();
      if ( prevData )
      {
            location.row = prevData->cursor.row;
            location.col = prevData->cursor.col;
      }
      else
      {
            location.row = 0;
            location.col = 0;
      }
      TiXmlParsingData data( p, TabSize(), location.row, location.col );
      location = data.Cursor();

      if ( encoding == TIXML_ENCODING_UNKNOWN )
      {
            // Check for the Microsoft UTF-8 lead bytes.
            const unsigned char* pU = (const unsigned char*)p;
            if (  *(pU+0) && *(pU+0) == TIXML_UTF_LEAD_0
                   && *(pU+1) && *(pU+1) == TIXML_UTF_LEAD_1
                   && *(pU+2) && *(pU+2) == TIXML_UTF_LEAD_2 )
            {
                  encoding = TIXML_ENCODING_UTF8;
                  useMicrosoftBOM = true;
            }
      }

    p = SkipWhiteSpace( p, encoding );
      if ( !p )
      {
            SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN );
            return 0;
      }

      while ( p && *p )
      {
            TiXmlNode* node = Identify( p, encoding );
            if ( node )
            {
                  p = node->Parse( p, &data, encoding );
                  LinkEndChild( node );
            }
            else
            {
                  break;
            }

            // Did we get encoding info?
            if (    encoding == TIXML_ENCODING_UNKNOWN
                   && node->ToDeclaration() )
            {
                  TiXmlDeclaration* dec = node->ToDeclaration();
                  const char* enc = dec->Encoding();
                  assert( enc );

                  if ( *enc == 0 )
                        encoding = TIXML_ENCODING_UTF8;
                  else if ( StringEqual( enc, "UTF-8", true, TIXML_ENCODING_UNKNOWN ) )
                        encoding = TIXML_ENCODING_UTF8;
                  else if ( StringEqual( enc, "UTF8", true, TIXML_ENCODING_UNKNOWN ) )
                        encoding = TIXML_ENCODING_UTF8;     // incorrect, but be nice
                  else 
                        encoding = TIXML_ENCODING_LEGACY;
            }

            p = SkipWhiteSpace( p, encoding );
      }

      // Was this empty?
      if ( !firstChild ) {
            SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, encoding );
            return 0;
      }

      // All is well.
      return p;
}


Generated by  Doxygen 1.6.0   Back to index