MSXML2 appendChild method fails in debugger only

I have a method that will dynamically build an XML schema based on schema fragments provided by upstream clients.  The mergeSchema method takes the various fragments each time this method is called and merges them into the fullSchema .  At this point, the method is not eliminating duplicates, (that's what I'm trying to code)

On the line marked by '*****, I'm getting an error message when I work in the VB debugger, namely "The parameter is invalid".  But when I compile it and run, the same line does its work and executes.  Is there a way to work around this and still get the same behavior?

Private Sub IToldSchemaMerger_mergeSchema(schemaChanges As MSXML2.IXMLDOMNode, fullSchema As MSXML2.IXMLDOMNode, ByVal schemaID As Long)
    Dim currentItem As MSXML2.IXMLDOMElement
    Dim dupe As MSXML2.IXMLDOMNode
    Dim fullyMatchingNode As MSXML2.IXMLDOMNode
    Dim l_schemaBase As MSXML2.IXMLDOMNode
    Dim l_fullSchema As MSXML2.IXMLDOMElement
    Dim l_throwAwayElements As MSXML2.IXMLDOMNode
    Set dom = CreateObject("MSXML2.DOMDocument")
    m_schemaID = schemaID
    dom.loadXML (fullSchema.xml)

    Set l_throwAwayElements = dom.createNode(NODE_ELEMENT, "THROW_AWAY", vbNullString)
    Set l_schemaBase = schemaChanges.selectSingleNode("/SCHEMA_CHANGES")
    removeNSAttribute l_schemaBase
    Set l_fullSchema = dom.selectSingleNode("/schema")

    'for each complexType in schemaChanges,
    With l_schemaBase.childNodes
        While .length > 0
            Set dupe = duplicateEntry(l_fullSchema, .item(0))

'            if the complexType already exists
             If dupe Is Nothing Then
                'add the complexType to the schema
                l_fullSchema.appendChild .item(0)   '*****
                'compare more closely and either drop it or alter the complexType name
               Set fullyMatchingNode = identicalNodes(dupe, .item(0))
               If fullyMatchingNode Is Nothing Then
                    'remove the item from the schema additions
                    l_throwAwayElements.appendChild .item(0)
                    Set currentItem = .item(0)
                    mergeSimilarComplexTypes l_schemaBase, currentItem
                    'Set currentItem = Nothing

               End If
             End If
    End With

    removeNSAttribute l_fullSchema

    Set fullSchema = l_fullSchema
End Sub
Who is Participating?
SpideyModConnect With a Mentor Commented:
per recommendation

Community Support Moderator @Experts Exchange
What if you declare I_fullschema of type IXMLDOMNode instead of IXMLDOMElement?

Have you downloaded the latest service packs for the XML3.0 parser?
You should change the progid to MSXML2.DOMDocument30 or MSXML2.DOMDocument40 and see if that makes a difference.
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

also, there is something interesting happening here:

If dupe Is Nothing Then
'add the complexType to the schema
l_fullSchema.appendChild .item(0)   '*****

End If

You are using the While .length > 0
and then stripping one child from one DOM to another.

The debugger may be caching the length of the childNodes. The question here is at which point of the loop do you get the error message.
tom_uf87Author Commented:
Thanks for the ideas folks.

I tried IXMLDOMNode instead of IXMLDOMElement -- no difference

I'm using the MSXML4 parser, and got the latest service pack.

The interesting part,

l_fullSchema.appendChild .item(0)   '*****

is the essence of the method.  It is examining XML from l_schemaBase.childNodes, and throwing away exact duplicates or moving the unique items into the fullSchema.  One thing I tried was to put .item(0) in either an XMLDOMNode or XMLDOMElement.  It still fails on the appendChild step.  Again, this is only in the debugger.  Compiled it works as desired.  

Another thing I tried was to replace the above line with the following two lines:

Set nonMatchingNode = .item(0)
l_fullSchema.appendChild nonMatchingNode

I also tried DOMDOcument30 and 40, to no effect.

While it is nice that the compiled code works as desired, I'd like to have this working in the debugger so I can add functionality to the method.
One thing I noticed about the debugger is that in some circumstances, late-binding causes a problem. Why not use early-binding? It might solve the "bug".

Dim dom AS Msxml2.DOMDocument40
Set dom = New Msxml2.DOMDocument40
tom_uf87Author Commented:
Another good idea, but, alas, it made no difference.  I also re-read previous questions and realized I didn't answer the one about where in the looping process it fails.  The failure is the first time the appendChild is encountered.

This question could be phrased another way:
If I can't use this approach to appendChildren from another bit of XML to my main XML, what should I be doing?
Hi tom_uf87,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Refund points and save as a 0-pt PAQ.

tom_uf87, Please DO NOT accept this comment as an answer.
EXPERTS: Post a comment if you are certain that an expert deserves credit.  Explain why.
DanRollins -- EE database cleanup volunteer
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.