Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Create XML within an activeX DLL

Posted on 2002-05-24
7
Medium Priority
?
230 Views
Last Modified: 2010-05-18
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
0
Comment
Question by:AlfaNoMore
  • 4
  • 3
7 Comments
 
LVL 23

Accepted Solution

by:
b1xml2 earned 400 total points
ID: 7032041
that cos you are calling a function without accepting a returned value,
Normally to save time this is what I do,

And the code can be streamlined.

  Public Function GetPsychometricsXML(GUID As String, _
    RefNo As String) As MSXML2.DOMDocument
  Set GetPsychometricsXML = New MSXML2.DOMDocument
  With GetPsychometricsXML
    .async = False
    .appendChild .createProcessingInstruction("xml","version='1.0' encoding='iso-8859-1'")
    .appendChild .createElement("RetrievePsychometricsRS")
  End With
  End Function
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 7032047
Plus the answer to your question is, (without the brackets)
objXML.appendChild objPI
0
 
LVL 9

Author Comment

by:AlfaNoMore
ID: 7032064
VB stuck those brackets in for me!!! It won't let me do it without them?
0
Industry Leaders: 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!

 
LVL 9

Author Comment

by:AlfaNoMore
ID: 7032087
As usual, top marks...

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

.selectSingleNode("RetrievePsychometricsRS").appendChild .createElement("Something")
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 7032090
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 =)
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 7032111
better is this

.documentElement.appendChild .createElement("Hello")
0
 
LVL 9

Author Comment

by:AlfaNoMore
ID: 7032146
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!
0

Featured Post

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.

Question has a verified solution.

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

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Integration Management Part 2
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

916 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