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. XML / XSL
  4. MSXML: troubles with "insertBefore" in Microsoft Visual C++

MSXML: troubles with "insertBefore" in Microsoft Visual C++

Scheduled Pinned Locked Moved XML / XSL
c++xmllinuxquestionannouncement
1 Posts 1 Posters 0 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.
  • B Offline
    B Offline
    Bash
    wrote on last edited by
    #1

    Hi Gurus! I have the simplest xml document (d:\\book.xml): <?xml version="1.0"?> <Report> ... </Report> I've written the small program (inserting XSL reference in the prolog): Dim xmlDoc,pi,ref set xmlDoc = CreateObject ("Msxml.DOMDocument") xmlDoc.async = false xmlDoc.resolveExternals = false xmlDoc.load ("d:\\book.xml") ref="type=""text/xsl"" href=""mysheet.xsl""" set pi = xmlDoc.createProcessingInstruction("xml-stylesheet",ref) xmlDoc.insertBefore pi,xmlDoc.childNodes.item(1) WScript.Echo(xmlDoc.xml) It works fine! Next, I tried to do the same using Microsoft Visual C++: IXMLDOMDocumentPtr XmlDocPtr; _bstr_t bstrXMLReport(_T("d:\\book.xml"); VARIANT_BOOL vtResult; HRESULT hr = XmlDocPtr.CreateInstance(MSXML::CLSID_DOMDocument); if (FAILED(hr)) { AfxMessageBox("Failed to CreateInstance(CLSID_DOMDocument)"); return; }; XmlDocPtr->async=FALSE; XmlDocPtr->resolveExternals=FALSE; vtResult=XmlDocPtr->load(bstrXMLReport); if (vtResult == VARIANT_FALSE) { AfxMessageBox("Failed to load XML document"); return; }; IXMLDOMProcessingInstructionPtr pi; _bstr_t bstrTarget(_T("xml-stylesheet")); _bstr_t bstrData(_T("type=\"text/xsl\" href=\"mysheet.xsl\"")); pi=XmlDocPtr->createProcessingInstruction(bstrTarget,bstrData); BSTR qqq; pi->get_xml(&qqq); CComVariant varRef; IXMLDOMNodePtr pFirst,pXMLNodeCur; XmlDocPtr->childNodes->get_item(1,&pFirst); varRef=pFirst; try { XmlDocPtr->insertBefore(pi,t); AfxMessageBox(XmlDocPtr->xml); } catch(_com_error &er) { TCHAR szErr[MAX_PATH]; memset(szErr,0,sizeof(szErr)); _tcscpy(szErr,(LPCTSTR)er.Description()); AfxMessageBox(szErr); }; After that, I've got the exception "The parameter is incorrect." Why? I suspect the incorrect usage of insertBefore method. What should I do? Yours sincerely, Alex Bash

    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