Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

IXMLDOMDocument::insertBefore()

Posted on 2004-11-30
5
Medium Priority
?
1,307 Views
Last Modified: 2010-05-18
I am using MSXML to generate an XML document.  I use the loadXML method to generate the DOCTYPE node and then need to add the processing instruction above the DocType.  I am trying to use insertBefore to do it, but can't seem to get the refChild argument right.  Could someone give me a hand?  I guess I am not sure in what format the pointer to the IXMLDOMNode is supposed to be assigned to a VARIANT.  This was my best guess, but it always fails at the insertBefore call.  Below is the code:

.
.
.
    //Create DocType Reference
    hr = pDoc->loadXML(L"<!DOCTYPE Test SYSTEM \"Test.dtd\">\n<Test></Test>", &varResult);
    if(hr!=S_OK || varResult!=VARIANT_TRUE){
        if(pDoc->get_parseError(&pXMLErr)==S_OK){
            if(node.Import(pXMLErr)){
                strError.Format("Unable to build XML file.  %s.", node.text);
                throw strError;
            }
            pXMLErr->Release();
            pXMLErr=NULL;
        }
        strError = "Unable to build XML file.  The file may be reserved by the operating system.";
        throw strError;
    }

    if(pDoc->get_childNodes(&pNodes)!=S_OK){
        strError = "Unable to create root element.";
        throw strError;
    }

    //Create Processing Instruction
    if(pNodes->get_item(0, &pDocType)!=S_OK){
        strError = "Unable to create root element.";
        throw strError;
    }
    VariantInit(&varRefChild);
    varRefChild.vt = VT_UI4;
    varRefChild.uiVal = (unsigned int) pDocType;
    if(pDoc->createProcessingInstruction(L"xml", L"version=\"1.0\" encoding=\"UTF-8\"", &pProcessInstruction)!=S_OK){
        strError = "Unable to create xml processing instruction.";
        throw strError;
    }
    if(pDoc->insertBefore(pProcessInstruction, varRefChild, &pNode)!=S_OK){
        strError = "Unable to add xml processing instruction.";
        throw strError;
    }
    pDocType.Release();
    pNode.Release();
    pProcessInstruction.Release();
.
.
.

Thanks,
David Johns
0
Comment
Question by:david_johns
  • 2
4 Comments
 
LVL 12

Expert Comment

by:andrewjb
ID: 12714161
Don't use variants, just use an IXMLDOMNode, which is an interface pointer.

0
 

Author Comment

by:david_johns
ID: 12714531
andrewjb,

I don't understand what you mean.  I try:

    if(pDoc->insertBefore(pProcessInstruction, pDocType, &pNode)!=S_OK){

where pDocType is defined as MSXML2::IXMLDOMNodePtr pDocType=NULL,

and I get:

error C2664: 'insertBefore' : cannot convert parameter 2 from 'class _com_ptr_t<class _com_IIID<struct MSXML2::IXMLDOMNode,&struct __s_GUID
 _GUID_2933bf80_7b36_11d2_b20e_00c04f983e60> >' to 'struct tagVARIANT'

I tried using &pDocType and *pDocType as well.  Could you explain what you mean?

Thanks,
David
0
 

Author Comment

by:david_johns
ID: 12738538
Got it...:

    //Create Processing Instruction
    if(pNodes->get_item(0, &pDocType)!=S_OK){
        strError = "Unable to create root element.";
        throw strError;
    }
    varRefChild.vt = VT_UKNOWN;
    varRefChild.punkVal= (IUnknown*) pDocType;
    if(pDoc->createProcessingInstruction(L"xml", L"version=\"1.0\" encoding=\"UTF-8\"", &pProcessInstruction)!=S_OK){
        strError = "Unable to create xml processing instruction.";
        throw strError;
    }
    if(pDoc->insertBefore(pProcessInstruction, varRefChild, &pNode)!=S_OK){
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 13140018
PAQed with points refunded (250)

modulo
Community Support Moderator
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question