MSXML2 appendChild method fails in debugger only

Posted on 2002-05-28
Medium Priority
Last Modified: 2008-02-26
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
Question by:tom_uf87
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 28

Expert Comment

ID: 7039483
What if you declare I_fullschema of type IXMLDOMNode instead of IXMLDOMElement?

Have you downloaded the latest service packs for the XML3.0 parser?
LVL 23

Expert Comment

ID: 7039722
You should change the progid to MSXML2.DOMDocument30 or MSXML2.DOMDocument40 and see if that makes a difference.
LVL 23

Expert Comment

ID: 7039736
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.
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Author Comment

ID: 7040095
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.
LVL 23

Expert Comment

ID: 7040585
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

Author Comment

ID: 7041642
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?
LVL 49

Expert Comment

ID: 7851199
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

Accepted Solution

SpideyMod earned 0 total points
ID: 7912828
per recommendation

Community Support Moderator @Experts Exchange

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

764 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