Uploaded image for project: 'Xerces-C++'
  1. Xerces-C++
  2. XERCESC-1620

whitespace lost in schema validation

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.7.0
    • None
    • SAX/SAX2
    • None
    • Windows 2000 SP4
      Visual Studio .NET 2003

    Description

      When XMLSchema validation is enabled, some whitespaces are reported neither characters() nor ignorableWhitespace() event.

      Following is output of sample program which is attached below.

      <characters>1234 5678 1234 5678 1234 5678 1234 5678</characters>
      <characters> 1234 5678 1234 5678 1234 5678 1234 5678 1234 5678</characters>
      <characters>1234 5678 1234 5678 1234 5678 1234 5678</characters>
      <characters> 1234 5678</characters>

      Between the 2nd and 3rd characters() event, whitespace is lost.

      Is it distinguishable the last token of 2nd event and first token of 3rd event are differenet words or parts of continuous word?

      Regards,

      Takashi Matsuda.
      ======================

      Sample Program:

      #include <xercesc/sax2/XMLReaderFactory.hpp>
      #include <xercesc/sax2/DefaultHandler.hpp>
      #include <xercesc/util/PlatformUtils.hpp>
      #include <xercesc/util/XMLString.hpp>
      #include <xercesc/framework/MemBufInputSource.hpp>

      #include <iostream>

      #ifndef SCHEMA_VALIDATION
      #define SCHEMA_VALIDATION 1
      #endif

      using namespace XERCES_CPP_NAMESPACE;

      static const char source[] =
      "<?xml version='1.0' encoding='ascii' ?>\n"
      "<list xmlns='http://myNameSpace/'\n"
      " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'\n"
      " xsi:schemaLocation='http://myNameSpace/ schema.xsd'\n"
      ">\n"
      " 1234 5678\n"
      " 1234 5678\n"
      " 1234 5678\n"
      " 1234 5678\n"
      " 1234 5678\n"
      " 1234 5678\n"
      " 1234 5678\n"
      " 1234 5678\n"
      " 1234 5678\n"
      " 1234 5678\n"
      " 1234 5678\n"
      " 1234 5678\n"
      " 1234 5678\n"
      " 1234 5678\n"
      "</list>";

      static const char schema[] =
      "<?xml version='1.0' encoding='ascii' ?>\n"
      "<xsd:schema\n"
      " xmlns:xsd='http://www.w3.org/2001/XMLSchema'\n"
      " targetNamespace='http://myNameSpace/'\n"
      " xmlns='http://myNameSpace/'\n"
      ">\n"
      "<xsd:element name='list' type='list_type' />\n"
      "<xsd:simpleType name='list_type'>\n"
      "<xsd:list itemType='xsd:unsignedInt' />\n"
      "</xsd:simpleType>\n"
      "</xsd:schema>";

      class MyHandler : public DefaultHandler
      {
      public:
      void characters(const XMLCh* const chars, const unsigned int length)

      { std::wstring message(chars, length); std::wcout << "<characters>" << message.c_str() << "</characters>" << std::endl; }

      void ignorableWhitespace(const XMLCh* const chars, const unsigned int length)

      { std::wstring message(chars, length); std::wcout << "<ignorableWhitespace>" << message.c_str() << "</ignorableWhitespace>" << std::endl; }

      };

      int main(int argc, char* argv[])
      {
      XMLPlatformUtils::Initialize();

      { SAX2XMLReader *parser = XMLReaderFactory::createXMLReader(); MyHandler myHandler; MemBufInputSource inputSource(reinterpret_cast<const XMLByte* const>(source), sizeof(source), "source.xml"); MemBufInputSource inputSchema(reinterpret_cast<const XMLByte* const>(schema), sizeof(schema), "schema.xsd"); #if SCHEMA_VALIDATION parser->loadGrammar(inputSchema, Grammar::SchemaGrammarType, true); parser->setFeature(XMLUni::fgXercesDynamic, true); #else parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, false); parser->setFeature(XMLUni::fgXercesSchema, false); #endif parser->setContentHandler(&myHandler); parser->setInputBufferSize(64); parser->parse(inputSource); delete parser; }

      XMLPlatformUtils::Terminate();

      return 0;
      }

      Attachments

        Activity

          People

            Unassigned Unassigned
            matsu Takashi Matsuda
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: