extra newline after declaration in 1st use of DOMWriter
-------------------------------------------------------

                 Key: XERCESC-1953
                 URL: https://issues.apache.org/jira/browse/XERCESC-1953
             Project: Xerces-C++
          Issue Type: Bug
          Components: DOM
    Affects Versions: 2.8.0
         Environment: Solaris 10
            Reporter: tommy klehr
            Priority: Minor



the sample program produces different output from DOMWriter although it's using 
the same input.
The first output has an extra newline after the declaration.  The second output 
has the document element on the same line as the declaration.

-------------------------------------------------

[mynah63.dev.sol10] $ ./tc                
impl = 4df4c
theSerializer = 58764
can set it to discarddefaultcontent
can set it to formatprettyprint
rc from writeNote() = 1
value = 
'<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<note> 
 <to>Tove</to> 
  <from>Jani</from>
  <heading>Reminder</heading>
  <salutation>Dear</salutation>
  <body>Don't forget me this weekend!</body> 
</note>
'
next take...
impl = 4df4c
theSerializer = 5a144
can set it to discarddefaultcontent
can set it to formatprettyprint
rc from writeNote() = 1
value = 
'<?xml version="1.0" encoding="UTF-8" standalone="yes" ?><note> 
 <to>Tove</to> 
  <from>Jani</from>
  <heading>Reminder</heading>
  <salutation>Dear</salutation>
  <body>Don't forget me this weekend!</body> 
</note>
'
$ 
-------------------------------------------------

#include <assert.h>
#include <unistd.h>
#include <iostream.h>
#include <sstream>
#include <fstream>
#include <string.h>
#include <rw/cstring.h>

#include <xalanc/Include/PlatformDefinitions.hpp>
#include <xalanc/Include/XalanVector.hpp>

#include <xalanc/Include/STLHelper.hpp>
#include <xalanc/XalanDOM/XalanDocument.hpp>
#include <xalanc/XalanDOM/XalanElement.hpp>

#include <xalanc/PlatformSupport/DirectoryEnumerator.hpp>
#include <xalanc/PlatformSupport/DOMStringHelper.hpp>
#include <xalanc/PlatformSupport/ExecutionContext.hpp>

#include <xalanc/DOMSupport/DOMServices.hpp>

#include <xalanc/XPath/XObjectFactoryDefault.hpp>
#include <xalanc/XPath/XPath.hpp>
#include <xalanc/XPath/XPathConstructionContextDefault.hpp>
#include <xalanc/XPath/XPathEnvSupportDefault.hpp>
#include <xalanc/XPath/XPathExecutionContextDefault.hpp>
#include <xalanc/XPath/XPathInit.hpp>
#include <xalanc/XPath/XPathProcessorImpl.hpp>
#include <xalanc/XPath/XPathFactoryDefault.hpp>
#include <xalanc/XPath/XPathEvaluator.hpp>

#include <xalanc/XalanSourceTree/XalanSourceTreeDOMSupport.hpp>
#include <xalanc/XalanSourceTree/XalanSourceTreeInit.hpp>
#include <xalanc/XalanSourceTree/XalanSourceTreeParserLiaison.hpp>

#include <xalanc/XalanTransformer/XalanTransformer.hpp>
#include <xalanc/XalanTransformer/XercesDOMWrapperParsedSource.hpp>
#include <xalanc/XalanTransformer/XalanSourceTreeWrapperParsedSource.hpp>
#include <xalanc/XSLT/ProblemListener.hpp>

//These includes are for converting XML document into String
#include <xalanc/PlatformSupport/XalanOutputStreamPrintWriter.hpp>
#include <xalanc/PlatformSupport/XalanStdOutputStream.hpp>
#include <xalanc/XMLSupport/FormatterToXML.hpp>
#include <xalanc/XMLSupport/FormatterTreeWalker.hpp>
#include <xalanc/XMLSupport/XMLSupportInit.hpp>
#include <xalanc/XercesParserLiaison/XercesDOMSupport.hpp>
#include <xalanc/XercesParserLiaison/XercesParserLiaison.hpp>
#include <xalanc/XercesParserLiaison/XercesDocumentWrapper.hpp>
#include <xalanc/XalanDOM/XalanNodeList.hpp>
#include <xalanc/XalanDOM/XalanDOMException.hpp>
#include <xalanc/XPath/XalanXPathException.hpp>
#include <xalanc/XPath/XPathParserException.hpp>
//#include <xalanc/XercesParserLiaison/Deprecated/XercesDocumentBridge.hpp>


//For Xerces DOM usage
#include <xercesc/util/XMLString.hpp>
#include <xercesc/util/XMLException.hpp>
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/dom/DOM.hpp>
#include <xercesc/dom/DOMNode.hpp>
#include <xercesc/dom/DOMNamedNodeMap.hpp>
//#include <xercesc/dom/DOMWriterFilter.hpp>
#include <xercesc/dom/DOMException.hpp>
#include <xercesc/dom/DOMDocument.hpp>
#include <xercesc/framework/LocalFileInputSource.hpp> // This is needed for 
const LocalFileInputSource      theInputSource(theFileName.c_str());
#include <xercesc/framework/MemBufInputSource.hpp> // This is needed for const 
MemBufInputSource      theInputSource(theFileName.c_str());
#include <xercesc/framework/MemBufFormatTarget.hpp>
#include <xercesc/parsers/XercesDOMParser.hpp>
//#include <xercesc/dom/deprecated/DOM_Node.hpp>
#include <xercesc/dom/DOMNodeFilter.hpp>
#include <xercesc/dom/DOMImplementation.hpp>
#include <xercesc/dom/DOMImplementationLS.hpp>
#include <xercesc/dom/DOMWriter.hpp>
#include <xercesc/framework/StdOutFormatTarget.hpp>
#include <xercesc/framework/LocalFileFormatTarget.hpp>
#include <xercesc/util/XMLUniDefs.hpp>
#include <xercesc/dom/DOM.hpp>

XALAN_USING_STD(cerr)
XALAN_USING_STD(endl)
XALAN_USING_STD(ostream)
XALAN_USING_STD(ifstream)

XALAN_USING_XALAN(XalanDocument)
XALAN_USING_XALAN(XPathEvaluator)
XALAN_USING_XALAN(XalanDOMString)
XALAN_USING_XALAN(XalanSourceTreeInit)
XALAN_USING_XALAN(XercesDOMSupport)
XALAN_USING_XALAN(XercesParserLiaison)
XALAN_USING_XALAN(XalanVector)
XALAN_USING_XALAN(ExecutionContext)
XALAN_USING_XALAN(MemoryManagerType)



//For Xerces DOM usage
XALAN_USING_XERCES(XMLPlatformUtils)
XALAN_USING_XERCES(DOMNode)
XALAN_USING_XERCES(DOMNamedNodeMap)
XALAN_USING_XERCES(XMLString)
XALAN_USING_XERCES(DOMImplementation)
XALAN_USING_XERCES(DOMImplementationRegistry)
XALAN_USING_XERCES(DOMWriter)
XALAN_USING_XERCES(DOMImplementationLS)
XALAN_USING_XERCES(XMLUni)
//XALAN_USING_XERCES(DOMWriterFilter)
XALAN_USING_XERCES(DOMErrorHandler)
XALAN_USING_XERCES(XMLFormatTarget)
//XALAN_USING_XERCES(DOMWriterFilter)
XALAN_USING_XERCES(LocalFileInputSource) //const LocalFileInputSource      
theInputSource(theFileName.c_str());
XALAN_USING_XERCES(MemBufInputSource) 
XALAN_USING_XERCES(MemBufFormatTarget)
XALAN_USING_XERCES(XMLException)
XALAN_USING_XERCES(DOMException)
XALAN_USING_XERCES(DOMNodeFilter)
  XALAN_USING_XERCES(LocalFileFormatTarget)

//For XPath
XALAN_USING_XALAN(XPathEvaluator)
XALAN_USING_XALAN(XObjectPtr)
XALAN_USING_XALAN(XalanNode)
XALAN_USING_XALAN(XalanElement)
XALAN_USING_XALAN(XalanDOMException)
XALAN_USING_XALAN(XalanXPathException)
XALAN_USING_XALAN(XPathParserException)
XALAN_USING_XALAN(NodeRefList)

//For Transformer
XALAN_USING_XALAN(XalanCompiledStylesheet)
XALAN_USING_XALAN(XalanDOMString)
XALAN_USING_XALAN(XalanTransformer)
XALAN_USING_XALAN(XSLTInputSource)
XALAN_USING_XALAN(XSLTResultTarget)
XALAN_USING_XALAN(XalanNamedNodeMap)

        XALAN_USING_XALAN(XalanStdOutputStream)
        XALAN_USING_XALAN(XalanOutputStreamPrintWriter)
        XALAN_USING_XALAN(FormatterToXML)
        XALAN_USING_XALAN(FormatterTreeWalker)
        XALAN_USING_XERCES(DOMDocument);
        XALAN_USING_XERCES(DOMElement);
        //XALAN_USING_XERCES(DOM_Node)
        XALAN_USING_XERCES(DOMText)
        XALAN_USING_XERCES(DOMDocumentType)
        XALAN_USING_XERCES(DOMDocumentFragment)
        XALAN_USING_XERCES(DOMTreeWalker)
        XALAN_USING_STD(stringstream)
        XALAN_USING_XERCES(MemBufInputSource)


int
mainX(int id, int argc, char *argv[])
{
  char filenameBuffer[1024];
  XercesDOMSupport      *theDOMSupportPtr;
  XercesParserLiaison *theLiaisonPtr;
  XalanDocument* theDocumentPtr;


  const char *text = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n<note> \n \
<to>Tove</to> \n\
<from>Jani</from>\n\
<heading>Reminder</heading>\n\
<salutation>Dear</salutation>\n\
<body>Don't forget me this weekend!</body> \n\
</note>\n\
";


  std::stringstream oss;
  std::string tooutput;




  //XalanSourceTreeInit                         theSourceTreeInit;
  theDOMSupportPtr=new XercesDOMSupport;
  theLiaisonPtr= new XercesParserLiaison(*theDOMSupportPtr);
  MemBufInputSource       inStream((XMLByte*)text, strlen(text), "Parser", 
false);
  const  XalanDOMString errorStr;
  theDocumentPtr = theLiaisonPtr->parseXMLStream(inStream,errorStr);



  XMLCh tempStr[100];
  XMLString::transcode("LS", tempStr, 99);
  DOMImplementation *impl = 
DOMImplementationRegistry::getDOMImplementation(tempStr);
  DOMWriter* theSerializer = ((DOMImplementationLS*)impl)->createDOMWriter();
  cout << "impl = " << impl << endl;
  cout << "theSerializer = " << theSerializer << endl;
  // optionally you can set some features on this serializer
  if (theSerializer->canSetFeature(XMLUni::fgDOMWRTDiscardDefaultContent, 
true)) {
    theSerializer->setFeature(XMLUni::fgDOMWRTDiscardDefaultContent, true);
    cerr << "can set it to discarddefaultcontent" << endl;
  }
  if (theSerializer->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true)) {
    theSerializer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
    cerr << "can set it to formatprettyprint" << endl;
  }
#if 0
  if (theSerializer->canSetFeature(XMLUni::fgDOMXMLDeclaration, false)) {
    theSerializer->setFeature(XMLUni::fgDOMXMLDeclaration, false);
    cerr << "can set it to declaration to false" << endl;
  }
#endif

  XMLFormatTarget *myFormTarget;
  sprintf(filenameBuffer, "/tmp/xmy_tjk.%d.%d", getpid(), id);
  myFormTarget = new 
LocalFileFormatTarget(XMLString::transcode(filenameBuffer));

  DOMDocument*   Domdoc = 
(DOMDocument*)theLiaisonPtr->mapToXercesDocument(theDocumentPtr);
  DOMNode *doc = Domdoc->getDocumentElement();

  Domdoc->setStandalone(true);
  Domdoc->normalize();

  bool rc = false;
  rc = theSerializer->writeNode(myFormTarget, *Domdoc);
  cerr << "rc from writeNote() = " << rc << endl;
  
  //delete theSerializer;
  theSerializer->release();
  delete myFormTarget;

  ifstream is;
  is.open (filenameBuffer);
  RWCString outStr;
  outStr.readFile (is);
  is.close();
//  outStr = outStr.strip(RWCString::both,'\n');

  cout << "value = " << endl << "'" << outStr << "'" << endl;

  return 0;
}

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


    int rc;
    rc = mainX(1, argc, argv);
    cout << "next take..." << endl;
    rc = mainX(2, argc, argv);
    XPathEvaluator::terminate();
    XalanTransformer::terminate();
    XMLPlatformUtils::Terminate();

    return rc;

}
-----------------------------------
CC=/opt/studio11/SUNWspro/bin/CC -mt -pto -library=rwtools7_std -l++ -lCstd +w 
-DXMY_OPERATOR_INDEX_FIX -DUSE_NON_CONST -DXMY_TCL

XERCESCROOT=/nafs/mynah/Vendor/xerces-c++/2.8.0/Sun/SunOS5.10
XALANCROOT=/nafs/mynah/Vendor/xalan-c++/1.10.0-2.8.0/Sun/SunOS5.10

#Include paths will be added here
INCS=-I$(XERCESCROOT)/include -I$(XALANCROOT)/include

LIBS=  -L$(XERCESCROOT)/lib \
          -lxerces-depdom \
          -lxerces-c    \
          -L$(XALANCROOT)/lib \
          -lxalan-c 

#Any compiler specific flags can be added here
CFLAGS= -PIC -zmuldefs -DXTFUNCPROTO -DFUNCPROTO -D_POSIX_PTHREAD_SEMANTICS 
$(INCDIRS) -g


all: tc

clean:
        -rm -rf *.o *.so

.SUFFIXES: .C .o


tc.o:   tc.C
        $(CC) $(CFLAGS) -c tc.C $(INCS)

tc:     tc.o
        $(PURIFY) $(CC) $(CFLAGS) -o $@ \
        tc.o \
        $(INCS) \
        $(LIBS)

.KEEP_STATE:



-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to