Link to home
Start Free TrialLog in
Avatar of AlfaNoMore
AlfaNoMore

asked on

Create XML within an activeX DLL

I have the following short code. It looks fine, but for some reason I'm getting a "Run-time error '438'; Object doesn't support this property or method" on the appendChild() methods.

Anyone know why this isn't working fort me?


Public Function GetPsychometricsXML(GUID As String, RefNo As String) As MSXML2.DOMDocument
    Dim objXML As MSXML2.DOMDocument
    Dim objPI As MSXML2.IXMLDOMProcessingInstruction
    Dim objRoot As MSXML2.IXMLDOMNode
    Dim objNewNode As MSXML2.IXMLDOMNode
    Dim objRS As ADODB.Recordset
    Dim strSQL As String
   
    Set objXML = New MSXML2.DOMDocument
    'objXML.loadXML ("<xml version=""1.0""></xml>")
   
    '// ADD our Processing Instruction: <xml vesion="1.0" />
    Set objPI = objXML.createProcessingInstruction("xml", " version=""1.0""")
    objXML.appendChild (objPI) '<< ERROR HERE!!!
    Set objPI = Nothing
   
    '// CREATE our ROOT NodeSet <RetrievePsychometricsRS />
    Set objRoot = objXML.createNode(NODE_ELEMENT, "RetrievePsychometricsRS", "")
   
    '// CREATE the Experiences NodeSet <Experiences />
   
   
    objXML.appendChild (objRoot)
    Set objRoot = Nothing
   
    Set GetPsychometricsXML = objXML
    Set objXML = Nothing
   
End Function
ASKER CERTIFIED SOLUTION
Avatar of b1xml2
b1xml2
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Plus the answer to your question is, (without the brackets)
objXML.appendChild objPI
Avatar of AlfaNoMore
AlfaNoMore

ASKER

VB stuck those brackets in for me!!! It won't let me do it without them?
As usual, top marks...

If I wanted to add nodes within say the RetrievePsychometricsRS node, could I use:

.selectSingleNode("RetrievePsychometricsRS").appendChild .createElement("Something")
please notice if there is a space before the "(" . That means that objXML.append is trying to append an object called "(objPI)".

Anyways, try out the code I have posted =)
better is this

.documentElement.appendChild .createElement("Hello")
Sorry mate, but I'm having a nightmare time with this.

This is the function I have at the mo:

Public Function GetPsychometricsXML(GUID As String, _
    RefNo As String) As MSXML2.DOMDocument
   
    Dim objRS As ADODB.Recordset
    Dim strSQL As String
   
    Set GetPsychometricsXML = New MSXML2.DOMDocument
   
    With GetPsychometricsXML
        .async = False
        .appendChild .createProcessingInstruction("xml", " version=""1.0""")
        .appendChild .createElement("RetrievePsychometricsRS")
        .documentElement.appendChild .createElement("Experiences")
        .documentElement.appendChild .createElement("WorkingStyles")
    End With
End Function

It works, and everything's great, but I need to start adding a lot of content within the Experiences NodeSet, and I'm getting into a right mess.

How could I efficiently produce this XML?
    <Experiences>
        <NoOfItems>3</NoOfItems>
        <Items>
            <Item id="1" title="Do you have experience of using a computer keyboard?" elementName="skills_13" value="2">
                <Option id="1" type="radio" value="1" text="Little/no experience" />
                <Option id="2" type="radio" value="2" text="Occasional/some experience" />
                <Option id="3" type="radio" value="3" text="Considerable experience" />
            </Item>
        <Items>
    </Experiences>

I went down your route, but I had this:

        .documentElement.firstChild.appendChild .createElement("NoOfItems")

And then I have to add a value to this! I think it could get out of control pretty quickly!