Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. COM
  4. how to load xml schema from resource?

how to load xml schema from resource?

Scheduled Pinned Locked Moved COM
xmlhtmldatabasehelptutorial
1 Posts 1 Posters 5 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dolph_loe
    wrote on last edited by
    #1

    Hi I want to include an xml validation schema as a part of an executable. My problem is how to add the schema to the MSXML2::XMLSchemaCache40. I have a schema called 'setup.xsd', and m_schemaCache is a MSXML2::IXMLDOMSchemaCollection2 interface to XMLSchemaCache40. The following code works ('setup' is the namespace for the schema). hr = m_schemaCache->add(L"setup", L"Setup.xsd"); Now I want to load the schema from a resource. Since IXMLDOMSchemaCollection2::add only accepts url's or MSXML2::DOMDocument's, I decided to parse the xml data using DOMDocument, and then pass the DOMDocument over to the XMLSchemaCache40. In the following code, everything seems to be ok until I try to add the DOMDocument to the XMLSchemaCache40. The resource is loaded, The DOMDocument parses it, and no errors are found. The readyState of the DOMDocument is 4. //Create resource name from resource id wchar_t sResName[10]; swprintf_s(sResName, 10, L"#%d", resourceId); //Locate the resource TCHAR sRestype[13] = _T("SCHEMA"); HRSRC hres = FindResource(NULL, sResName, sRestype); if (hres == 0) { return false; } //If resource is found a handle to the resource is returned //now just load the resource HGLOBAL hbytes = LoadResource(NULL, hres); // Lock the resource LPVOID pdata = LockResource(hbytes); //Convert the resource text file to data we can use LPBYTE sData = (LPBYTE)pdata; BSTR sXml = _bstr_t((char*) sData); //Crate instance of DOM parser MSXML2::IXMLDOMDocument* doc; hr = CoCreateInstance(__uuidof(MSXML2::DOMDocument), NULL, CLSCTX_ALL, __uuidof(MSXML2::IXMLDOMDocument), (void**) &doc); if (FAILED(hr)) return false; //We don't want async read doc->put_async(VARIANT_FALSE); doc->put_validateOnParse(VARIANT_TRUE); //Parse the xml schema we just loaded from our resources VARIANT_BOOL succeeded; hr = doc->loadXML(sXml, &succeeded); if (succeeded != VARIANT_TRUE) { //Load failed return false; } //HERE IT FAILS!!!!!! //Add the loaded schema to the schema collection hr = m_schemaCache->add(bstrNamespace, _variant_t(doc)); if ( FAILED(hr) ) return false; return true; What am I doing wrong? Thanks in advance for any answers :) øivind

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups