Example #1
0
void SYSTEM::CXMLConfiguration::Parse(std::string xmlcontent)
{
    // ÅäÖýâÎö¹æÔò
    static const XMLCh gLS[] = { chLatin_L, chLatin_S, chNull };
    impl = DOMImplementationRegistry::getDOMImplementation(gLS);
    if(!impl)
        return;
//		throw CException(GET_TEXT(ERR_XML_DOM_IMPLEMENTATION));
    if(parser == NULL)
        parser = new XercesDOMParser;

    XercesDOMParser* xmlparser = (XercesDOMParser*)parser;

    xmlparser->setValidationScheme(XercesDOMParser::Val_Never);
    xmlparser->setLoadExternalDTD(false);

    xmlparser->setDoNamespaces(false);
    xmlparser->setDoSchema(false);
    xmlparser->setValidationSchemaFullChecking(false);
    xmlparser->setCreateEntityReferenceNodes(false);
    xmlparser->setIncludeIgnorableWhitespace(false);

    xmlparser->resetDocumentPool();	//ÖØÖÃÎĵµ»º³å³Ø

    MemBufInputSource input((XMLByte*) xmlcontent.c_str(), xmlcontent.size(), "memory");
    xmlparser->parse(input);
    doc = xmlparser->getDocument();
    if(doc)
        itemElement = ((XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument*)doc)->getDocumentElement();	//¸³Óè¸ù½Úµã
    else
        return;
//		throw CException(boost::str(boost::format(GET_TEXT(ERR_PARSE_CONFIG_FILE)) % xmlcontent));

}
Example #2
0
bool SYSTEM::CXMLConfiguration::Open(std::string xmlpath)
{
    // ÅäÖýâÎö¹æÔò
    static const XMLCh gLS[] = { chLatin_L, chLatin_S, chNull };
    impl = DOMImplementationRegistry::getDOMImplementation(gLS);
    if(!impl)
        return false;
//		throw CException(GET_TEXT(ERR_XML_DOM_IMPLEMENTATION));
    if(parser == NULL)
        parser = new XercesDOMParser;
    XercesDOMParser* xmlparser = (XercesDOMParser*)parser;
    xmlparser->setValidationScheme(XercesDOMParser::Val_Never);
    xmlparser->setDoNamespaces(false);
    xmlparser->setDoSchema(false);
    xmlparser->setValidationSchemaFullChecking(false);
    xmlparser->setCreateEntityReferenceNodes(false);
    xmlparser->setIncludeIgnorableWhitespace(false);

    xmlparser->resetDocumentPool();	//ÖØÖÃÎĵµ»º³å³Ø
    xmlparser->parse(xmlpath.c_str());
    doc = xmlparser->getDocument();
    if(doc)
        itemElement = ((XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument*)doc)->getDocumentElement();	//¸³Óè¸ù½Úµã
    else
        return false;
    //throw CException(boost::str(boost::format(GET_TEXT(ERR_PARSE_CONFIG_FILE)) % xmlpath));

    xmlFile = xmlpath;
    return true;
}
Example #3
0
void XMLRuntime::read(const string& filename, FreeAX25::Runtime::Configuration& config) {
    XercesDOMParser parser;
    parser.setValidationScheme(XercesDOMParser::Val_Always);
    parser.setDoNamespaces(true);
    parser.setDoSchema(true);
    parser.setDoXInclude(true);
    parser.setHandleMultipleImports(true);
    parser.setValidationSchemaFullChecking(true);
    parser.setCreateEntityReferenceNodes(false);
    parser.setIncludeIgnorableWhitespace(false);

    DOMTreeErrorReporter errReporter;
    parser.setErrorHandler(&errReporter);

    parser.parse(filename.c_str());

    if (errReporter.getSawErrors())
    	throw exception();

    // Now read configuration from the DOM Tree:
    XERCES_CPP_NAMESPACE::DOMDocument* doc = parser.getDocument();
    assert(doc != nullptr);

    auto rootElement = doc->getDocumentElement();
    auto configName = rootElement->getAttribute(toX("name"));
    config.setId(fmX(configName));

    { // Get settings:
		auto nodeList = rootElement->getElementsByTagName(toX("Settings"));
		if (nodeList->getLength() > 0)
			readSettings(
					"",
					static_cast<DOMElement*>(nodeList->item(0)),
					config.settings);
    }

    { // Get plugins:
		auto nodeList = rootElement->getElementsByTagName(toX("Plugins"));
		if (nodeList->getLength() > 0)
			readPlugins(
					"",
					static_cast<DOMElement*>(nodeList->item(0)),
					config.plugins);
    }
}
bool 
CategoryTranslationLoader::loadTranslations( const MC2String& filename ) try {
   // load and parse file
   XercesDOMParser parser;
   parser.setValidationScheme( XercesDOMParser::Val_Auto );
   parser.setIncludeIgnorableWhitespace( false );

   parser.parse( filename.c_str() );

   if ( parser.getDocument() == NULL ) {
      return false;
   }

   loadTranslations( parser.getDocument() );

   return true;

} catch ( const XMLTool::Exception& e ) {
   // any xml exception here is bad.
   return false;
}
Example #5
0
UINT APIENTRY CXMLDOMDocument::ParseThread(void *pParm)
{
	ATLTRACE(_T("CXMLDOMDocument::ParseThread\n"));

	CXMLDOMDocument *pThis = reinterpret_cast<CXMLDOMDocument *> (pParm);
	if (NULL == pThis)
		return 0;

	if (!pThis->m_bAbort && pThis->m_FileName.length() > 0) {
		CBindStatCallbackObj *pCallbackObj = NULL;
		HRESULT hr = CBindStatCallbackObj::CreateInstance(&pCallbackObj);
		if (S_OK != hr)
			pCallbackObj = NULL;

		if (pCallbackObj != NULL) {
			pCallbackObj->AddRef();
			pCallbackObj->m_pDoc = pThis;	
		}
		TCHAR name[MAX_PATH] = _T("");
		if (pThis->m_bAsync)
			pThis->PostMessage(MSG_READY_STATE_CHANGE,1);
		
		hr = URLDownloadToCacheFile(NULL,pThis->m_FileName,name,URLOSTRM_GETNEWESTVERSION,0,pCallbackObj);
		if (pCallbackObj != NULL)
			pCallbackObj->Release();

		if (E_ABORT == hr)
			pThis->m_bAbort = true;
		else {	
			if (S_OK != hr) {
				_bstr_t error = _T("Failed to download ") + pThis->m_FileName + _T(": ");
				_com_error comError(hr);
				error += comError.ErrorMessage();
				pThis->m_pParseError->SetData(1,pThis->m_FileName,error,_T(""),0,0,0);
				pThis->m_bParseError = true;
			}
		}

		if (S_OK == hr) {
			pThis->m_FileName = name;
			if (pThis->m_bAsync)
				pThis->PostMessage(MSG_READY_STATE_CHANGE,2);
		}
	}

	XercesDOMParser parser;

	//
	//   If set to true then an node supporting IXMLDOMProcessingInstruction
	//     is added for the XML declaration.
	//
	//   Setting to true in a custom DLL will better mimic
	//      MSXML.DLL but at a cost of conformance errors
	//      using David Brownell's suite
	//parser.setToCreateXMLDeclTypeNode(false);

	parser.setIncludeIgnorableWhitespace(pThis->m_bPreserveWhiteSpace);



	if (!pThis->m_bParseError && !pThis->m_bAbort) {
		parser.setDoValidation(pThis->m_bThreadValidate);
		//
		//   this brings the COM component into better mimicry to MSXML
		//      by not throwing a validation error when there is no DOCTYPE
		//
		parser.setValidationScheme(pThis->m_bThreadValidate ? AbstractDOMParser::Val_Auto : AbstractDOMParser::Val_Never);
	}

	if (!pThis->m_bParseError && !pThis->m_bAbort)
		parser.setErrorHandler(pThis);

	if (!pThis->m_bParseError && !pThis->m_bAbort)
		pThis->m_pParseError->Reset();
	
	if (!pThis->m_bParseError && !pThis->m_bAbort)
		pThis->m_bParseError = false;

	try
	{
		if (!pThis->m_bParseError && !pThis->m_bAbort) {
			if (pThis->m_FileName.length() > 0)
				parser.parse(static_cast<LPCTSTR> (pThis->m_FileName));
			else {
				XMLByte *pXMLByte =  reinterpret_cast<XMLByte*> (static_cast<XMLCh*>(pThis->m_xml));
				MemBufInputSource memBufIS(pXMLByte,pThis->m_xml.length()*sizeof(XMLCh),OLESTR("IBMXMLParser"),false);
				memBufIS.setEncoding(OLESTR("UTF-16LE"));
				if (!pThis->m_bParseError && !pThis->m_bAbort)
					parser.parse(memBufIS);
			}
		}

	}
	catch(...)
	{
		pThis->m_bParseError = true;
		return 0;
	}

	if (!pThis->m_bParseError && !pThis->m_bAbort)
		pThis->m_TmpDocument = parser.adoptDocument();

	if (!pThis->m_bParseError && !pThis->m_bAbort && pThis->m_bAsync)
		pThis->PostMessage(MSG_READY_STATE_CHANGE,4);
  	
	return 0;
}