Index  Source Files  Annotated Class List  Alphabetical Class List  Class Hierarchy  Graphical Class Hierarchy   
 

/home/orenmnero/autobuild/quickfix/src/C++/LIBXML_DOMDocument.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 ** Copyright (c) quickfixengine.org  All rights reserved.
00003 **
00004 ** This file is part of the QuickFIX FIX Engine
00005 **
00006 ** This file may be distributed under the terms of the quickfixengine.org
00007 ** license as defined by quickfixengine.org and appearing in the file
00008 ** LICENSE included in the packaging of this file.
00009 **
00010 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00011 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00012 **
00013 ** See http://www.quickfixengine.org/LICENSE for licensing information.
00014 **
00015 ** Contact ask@quickfixengine.org if any conditions of this licensing are
00016 ** not clear to you.
00017 **
00018 ****************************************************************************/
00019 
00020 #ifdef _MSC_VER
00021 #include "stdafx.h"
00022 #include <atlbase.h>
00023 #include <atlconv.h>
00024 #else
00025 #include "config.h"
00026 #endif
00027 #include "CallStack.h"
00028 
00029 #if (HAVE_LIBXML > 0 || _MSC_VER == 0)
00030 #include "LIBXML_DOMDocument.h"
00031 #include <libxml/xpath.h>
00032 #include <sstream>
00033 
00034 namespace FIX
00035 {
00036   bool LIBXML_DOMAttributes::get( const std::string& name, std::string& value )
00037   { QF_STACK_PUSH(LIBXML_DOMAttributes::get)
00038 
00039     xmlChar* result = xmlGetProp(m_pNode, (const xmlChar*)name.c_str());
00040     if(result == NULL) return false;
00041     value = (char*)result;
00042     return true;
00043 
00044     QF_STACK_POP
00045   }
00046 
00047   DOMAttributes::map LIBXML_DOMAttributes::toMap()
00048   { QF_STACK_PUSH(LIBXML_DOMAttributes::toMap)
00049 
00050     xmlAttr* attr = m_pNode->properties;
00051     DOMAttributes::map map;
00052     while( attr != 0 )
00053     {
00054       std::string value;
00055       std::string name;
00056       if( attr->name ) name = (char*)attr->name;
00057       get(name, value);
00058       map[name] = value;
00059       attr = attr->next;
00060     }
00061     return map;
00062 
00063     QF_STACK_POP
00064   }
00065 
00066   DOMNodePtr LIBXML_DOMNode::getFirstChildNode()
00067   { QF_STACK_PUSH(LIBXML_DOMNode::getFirstChildNode)
00068 
00069     if( !m_pNode->children ) return DOMNodePtr();
00070     xmlNodePtr pNode = m_pNode->children;
00071     if( pNode == NULL ) return DOMNodePtr();
00072     return DOMNodePtr(new LIBXML_DOMNode(pNode));
00073 
00074     QF_STACK_POP
00075   }
00076 
00077   DOMNodePtr LIBXML_DOMNode::getNextSiblingNode()
00078   { QF_STACK_PUSH(LIBXML_DOMAttributes::getNextSiblingNode)
00079 
00080     if( !m_pNode->next ) return DOMNodePtr();
00081     xmlNodePtr pNode = m_pNode->next;
00082     if( pNode == NULL ) return DOMNodePtr();
00083     return DOMNodePtr(new LIBXML_DOMNode(pNode));
00084 
00085     QF_STACK_POP
00086   }
00087 
00088   DOMAttributesPtr LIBXML_DOMNode::getAttributes()
00089   { QF_STACK_PUSH(LIBXML_DOMAttributes::getAttributes)
00090     return DOMAttributesPtr(new LIBXML_DOMAttributes(m_pNode));
00091     QF_STACK_POP
00092   }
00093 
00094   std::string LIBXML_DOMNode::getName()
00095   { QF_STACK_PUSH(LIBXML_DOMAttributes::getName)
00096     return m_pNode->name ? (char*)m_pNode->name : "";
00097     QF_STACK_POP
00098   }
00099 
00100   std::string LIBXML_DOMNode::getText()
00101   { QF_STACK_PUSH(LIBXML_DOMAttributes::getText)
00102     return m_pNode->content ? (char*)m_pNode->content : "";
00103     QF_STACK_POP
00104   }
00105 
00106   LIBXML_DOMDocument::LIBXML_DOMDocument() throw( ConfigError )
00107   : m_pDoc(NULL)
00108   {
00109   }
00110 
00111   LIBXML_DOMDocument::~LIBXML_DOMDocument()
00112   {
00113     xmlFreeDoc(m_pDoc);
00114   }
00115 
00116   bool LIBXML_DOMDocument::load( std::istream& stream )
00117   { QF_STACK_PUSH(LIBXML_DOMAttributes::load)
00118 
00119     try
00120     {
00121       std::stringstream sstream;
00122       sstream << stream.rdbuf();
00123       m_pDoc = xmlParseDoc((xmlChar*)sstream.str().c_str());
00124       return m_pDoc != NULL;
00125     }
00126     catch( ... ) { return false; }
00127 
00128     QF_STACK_POP
00129   }
00130 
00131   bool LIBXML_DOMDocument::load( const std::string& url )
00132   { QF_STACK_PUSH(LIBXML_DOMAttributes::lead)
00133 
00134     try
00135     {
00136       m_pDoc = xmlParseFile(url.c_str());
00137       return m_pDoc != NULL;
00138     }
00139     catch( ... ) { return false; }
00140 
00141     QF_STACK_POP
00142   }
00143 
00144   bool LIBXML_DOMDocument::xml( std::ostream& out )
00145   { QF_STACK_PUSH(LIBXML_DOMAttributes::xml)
00146     return false;
00147     QF_STACK_POP
00148   }
00149 
00150   DOMNodePtr LIBXML_DOMDocument::getNode( const std::string& XPath )
00151   { QF_STACK_PUSH(LIBXML_DOMAttributes::getNode)
00152 
00153     xmlXPathContextPtr context = xmlXPathNewContext(m_pDoc);
00154     xmlXPathObjectPtr xpathObject = xmlXPathEval((xmlChar*)XPath.c_str(), context);
00155 
00156     if( xpathObject == NULL
00157         || xpathObject->nodesetval == NULL
00158         || xpathObject->nodesetval->nodeNr != 1 )
00159     {
00160       xmlXPathFreeContext(context);
00161       return DOMNodePtr();
00162     }
00163 
00164     DOMNodePtr result(new LIBXML_DOMNode(xpathObject->nodesetval->nodeTab[0]));
00165     xmlXPathFreeContext(context);
00166     xmlXPathFreeObject(xpathObject);
00167     return result;
00168 
00169     QF_STACK_POP
00170   }
00171 }
00172 
00173 #endif

Generated on Mon Jul 24 19:36:29 2006 for QuickFIX by doxygen 1.3.6-20040222 written by Dimitri van Heesch, © 1997-2001