dbertoni    01/12/04 13:53:39

  Added:       c/samples/SerializeNodeSet foo.xml SerializeNodeSet.cpp
                        SerializeNodeSet.dsp
  Log:
  Initial revision.
  
  Revision  Changes    Path
  1.1                  xml-xalan/c/samples/SerializeNodeSet/foo.xml
  
  Index: foo.xml
  ===================================================================
  <?xml version="1.0"?>
  <doc>
    <name first="David" last="Marston"/>
    <name first="David" last="Bertoni"/>
    <name first="Donald" last="Leslie"/>
    <name first="Emily" last="Farmer"/>
    <name first="Myriam" last="Midy"/>
    <name first="Paul" last="Dick"/>
    <name first="Scott" last="Boag"/>
    <name first="Shane" last="Curcuru"/>
    <name first="Joseph" last="Kesselman"/>
    <name first="Stephen" last="Auriemma"/>
  </doc>
  
  
  1.1                  xml-xalan/c/samples/SerializeNodeSet/SerializeNodeSet.cpp
  
  Index: SerializeNodeSet.cpp
  ===================================================================
  // Base header file.  Must be first.
  #include <Include/PlatformDefinitions.hpp>
  
  
  
  #include <cassert>
  
  #if defined(XALAN_OLD_STREAM_HEADERS)
  #include <iostream.h>
  #else
  #include <iostream>
  #endif
  
  
  
  #include <util/PlatformUtils.hpp>
  #include <framework/LocalFileInputSource.hpp>
  
  
  
  #include <XalanDOM/XalanDocument.hpp>
  #include <XalanDOM/XalanElement.hpp>
  
  
  
  #include <PlatformSupport/XalanOutputStreamPrintWriter.hpp>
  #include <PlatformSupport/XalanStdOutputStream.hpp>
  
  
  
  #include <XPath/NodeRefList.hpp>
  #include <XPath/XObject.hpp>
  #include <XPath/XPathEvaluator.hpp>
  
  
  
  #include <XMLSupport/FormatterToXML.hpp>
  #include <XMLSupport/FormatterTreeWalker.hpp>
  #include <XMLSupport/XMLSupportInit.hpp>
  
  
  
  #include <XalanSourceTree/XalanSourceTreeDOMSupport.hpp>
  #include <XalanSourceTree/XalanSourceTreeInit.hpp>
  #include <XalanSourceTree/XalanSourceTreeParserLiaison.hpp>
  
  
  
  int
  main(
                        int                             argc,
                        const char*             argv[])
  {
  #if !defined(XALAN_NO_NAMESPACES)
        using std::cerr;
        using std::cout;
        using std::endl;
  #endif
  
        int             theResult = 0;
  
        if (argc != 4)
        {
                cerr << "Usage: SerializeNodeSet XMLFilePath Context XPathExpression" 
<< endl;
  
                theResult = -1;
        }
        else
        {
                try
                {
                        XMLPlatformUtils::Initialize();
  
                        XPathEvaluator::initialize();
  
                        {
                                // Initialize the XalanSourceTree subsystem...
                                XalanSourceTreeInit             theSourceTreeInit;
  
                                // Initialize the XMLSupport subsystem...
                                XMLSupportInit          theXMLSupportInit;
  
                                // We'll use these to parse the XML file.
                                XalanSourceTreeDOMSupport               theDOMSupport;
                                XalanSourceTreeParserLiaison    
theLiaison(theDOMSupport);
  
                                // Hook the two together...
                                theDOMSupport.setParserLiaison(&theLiaison);
  
                                // Create an input source that represents a local 
file...
                                const LocalFileInputSource      
theInputSource(c_wstr(XalanDOMString(argv[1])));
  
                                // Parse the document...
                                XalanDocument* const    theDocument =
                                                
theLiaison.parseXMLStream(theInputSource);
                                assert(theDocument != 0);
  
                                XPathEvaluator  theEvaluator;
  
                                // OK, let's find the context node...
                                XalanNode* const        theContextNode =
                                                theEvaluator.selectSingleNode(
                                                        theDOMSupport,
                                                        theDocument,
                                                        
XalanDOMString(argv[2]).c_str(),
                                                        
theDocument->getDocumentElement());
  
                                if (theContextNode == 0)
                                {
                                        cerr << "Error: No nodes matched the location 
path \""
                                                 << argv[2]
                                                 << "\"."
                                                 << endl
                                                 << "Execution cannot continue."
                                                 << endl
                                                 << endl;
                                }
                                else
                                {
                                        // OK, let's evaluate the expression...
                                        const NodeRefList       theResult =
                                                theEvaluator.selectNodeList(
                                                                theDOMSupport,
                                                                theContextNode,
                                                                
XalanDOMString(argv[3]).c_str(),
                                                                
theDocument->getDocumentElement());
  
                                        const NodeRefList::size_type    theLength = 
theResult.getLength();
  
                                        if (theLength == 0)
                                        {
                                                cerr << endl
                                                         << "Warning: No nodes matched 
the location path \""
                                                         << argv[3]
                                                         << "\"."
                                                         << endl
                                                         << endl;
                                        }
                                        else
                                        {
                                                // OK, we're going to serialize the 
nodes that were
                                                // found.  We should really check to 
make sure the
                                                // root (document) has not been 
selected, since we
                                                // really can't serialize a node list 
with the root.
                                                XalanStdOutputStream                   
 theStream(cout);
                                                XalanOutputStreamPrintWriter    
thePrintWriter(theStream);
  
                                                FormatterToXML                  
theFormatter(thePrintWriter);
                                                FormatterTreeWalker             
theWalker(theFormatter);
  
                                                // Don't write a header...
                                                
theFormatter.setShouldWriteXMLHeader(false);
  
                                                // It's required that we do this...
                                                theFormatter.startDocument();
  
                                                // Traverse the subtree of the 
document rooted at
                                                // each node we've selected...
                                                for (NodeRefList::size_type i = 0; i < 
theLength; ++i)
                                                {
                                                        const XalanNode* const  
theNode = theResult.item(i);
                                                        assert(theNode != 0);
  
                                                        const XalanNode::NodeType      
 theNodeType =
                                                                theNode->getNodeType();
  
                                                        if (theNodeType == 
XalanNode::DOCUMENT_NODE)
                                                        {
                                                                cerr << endl
                                                                         << "Warning: 
The root was selected.  The root cannot be serialized."
                                                                         << endl;
                                                        }
                                                        else if (theNodeType == 
XalanNode::ATTRIBUTE_NODE)
                                                        {
                                                                cerr << endl
                                                                         << "Warning: 
An attribute or namespace node was selected.  Attribute and namespace nodes cannot be 
serialized."
                                                                         << endl;
                                                        }
                                                        else
                                                        {
                                                                
theWalker.traverseSubtree(theNode);
                                                        }
                                                }
  
                                                // It's required that we do this...
                                                theFormatter.endDocument();
                                        }
                                }
                        }
  
                        XPathEvaluator::terminate();
  
                        XMLPlatformUtils::Terminate();
                }
                catch(...)
                {
                        cerr << "Exception caught!" << endl;
  
                        theResult = -1;
                }
        }
  
        return theResult;
  };
  
  
  
  1.1                  xml-xalan/c/samples/SerializeNodeSet/SerializeNodeSet.dsp
  
  Index: SerializeNodeSet.dsp
  ===================================================================
  # Microsoft Developer Studio Project File - Name="SerializeNodeSet" - Package 
Owner=<4>
  # Microsoft Developer Studio Generated Build File, Format Version 6.00
  # ** DO NOT EDIT **
  
  # TARGTYPE "Win32 (x86) Console Application" 0x0103
  
  CFG=SerializeNodeSet - Win32 Debug
  !MESSAGE This is not a valid makefile. To build this project using NMAKE,
  !MESSAGE use the Export Makefile command and run
  !MESSAGE 
  !MESSAGE NMAKE /f "SerializeNodeSet.mak".
  !MESSAGE 
  !MESSAGE You can specify a configuration when running NMAKE
  !MESSAGE by defining the macro CFG on the command line. For example:
  !MESSAGE 
  !MESSAGE NMAKE /f "SerializeNodeSet.mak" CFG="SerializeNodeSet - Win32 Debug"
  !MESSAGE 
  !MESSAGE Possible choices for configuration are:
  !MESSAGE 
  !MESSAGE "SerializeNodeSet - Win32 Release" (based on "Win32 (x86) Console 
Application")
  !MESSAGE "SerializeNodeSet - Win32 Debug" (based on "Win32 (x86) Console 
Application")
  !MESSAGE 
  
  # Begin Project
  # PROP AllowPerConfigDependencies 0
  # PROP Scc_ProjName ""
  # PROP Scc_LocalPath ""
  CPP=cl.exe
  RSC=rc.exe
  
  !IF  "$(CFG)" == "SerializeNodeSet - Win32 Release"
  
  # PROP BASE Use_MFC 0
  # PROP BASE Use_Debug_Libraries 0
  # PROP BASE Output_Dir "Release"
  # PROP BASE Intermediate_Dir "Release"
  # PROP BASE Target_Dir ""
  # PROP Use_MFC 0
  # PROP Use_Debug_Libraries 0
  # PROP Output_Dir "..\..\Build\Win32\VC6\Release"
  # PROP Intermediate_Dir "..\..\Build\Win32\VC6\Release\SerializeNodeSet"
  # PROP Ignore_Export_Lib 0
  # PROP Target_Dir ""
  # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" 
/YX /FD /c
  # ADD CPP /nologo /MD /W4 /GR /GX /O2 /Ob2 /I "..\..\..\..\xml-xerces\c\src" /I 
"..\..\src" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FD /c
  # SUBTRACT CPP /YX
  # ADD BASE RSC /l 0x409 /d "NDEBUG"
  # ADD RSC /l 0x409 /d "NDEBUG"
  BSC32=bscmake.exe
  # ADD BASE BSC32 /nologo
  # ADD BSC32 /nologo
  LINK32=link.exe
  # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib 
advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib 
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib 
ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console 
/machine:I386
  # ADD LINK32 ..\..\..\..\xml-xerces\c\Build\Win32\VC6\Release\xerces-c_1.lib /nologo 
/subsystem:console /machine:I386
  
  !ELSEIF  "$(CFG)" == "SerializeNodeSet - Win32 Debug"
  
  # PROP BASE Use_MFC 0
  # PROP BASE Use_Debug_Libraries 1
  # PROP BASE Output_Dir "Debug"
  # PROP BASE Intermediate_Dir "Debug"
  # PROP BASE Target_Dir ""
  # PROP Use_MFC 0
  # PROP Use_Debug_Libraries 1
  # PROP Output_Dir "..\..\Build\Win32\VC6\Debug"
  # PROP Intermediate_Dir "..\..\Build\Win32\VC6\Debug\SerializeNodeSet"
  # PROP Ignore_Export_Lib 0
  # PROP Target_Dir ""
  # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D 
"_MBCS" /YX /FD /GZ /c
  # ADD CPP /nologo /MDd /W4 /Gm /GR /GX /Zi /Od /I "..\..\..\..\xml-xerces\c\src" /I 
"..\..\src" /D "_CONSOLE" /D "WIN32" /D "_DEBUG" /D "_MBCS" /YX /FD /GZ /c
  # ADD BASE RSC /l 0x409 /d "_DEBUG"
  # ADD RSC /l 0x409 /d "_DEBUG"
  BSC32=bscmake.exe
  # ADD BASE BSC32 /nologo
  # ADD BSC32 /nologo
  LINK32=link.exe
  # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib 
advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib 
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib 
ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console 
/debug /machine:I386 /pdbtype:sept
  # ADD LINK32 ..\..\..\..\xml-xerces\c\Build\Win32\VC6\Debug\xerces-c_1D.lib /nologo 
/subsystem:console /map /debug /machine:I386 /pdbtype:sept
  
  !ENDIF 
  
  # Begin Target
  
  # Name "SerializeNodeSet - Win32 Release"
  # Name "SerializeNodeSet - Win32 Debug"
  # Begin Group "Source Files"
  
  # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
  # Begin Source File
  
  SOURCE=.\SerializeNodeSet.cpp
  # End Source File
  # End Group
  # Begin Group "Header Files"
  
  # PROP Default_Filter "h;hpp;hxx;hm;inl"
  # End Group
  # Begin Group "Resource Files"
  
  # PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
  # End Group
  # End Target
  # End Project
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to