Solved

Create XML within an activeX DLL

Posted on 2002-05-24
7
223 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
[X]
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
  • 4
  • 3
7 Comments
 
LVL 23

Accepted Solution

by:
b1xml2 earned 100 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
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

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

752 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