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.IXMLDOMProcessingIn struction
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.createProcessingIns truction(" xml", " version=""1.0""")
objXML.appendChild (objPI) '<< ERROR HERE!!!
Set objPI = Nothing
'// CREATE our ROOT NodeSet <RetrievePsychometricsRS />
Set objRoot = objXML.createNode(NODE_ELE MENT, "RetrievePsychometricsRS", "")
'// CREATE the Experiences NodeSet <Experiences />
objXML.appendChild (objRoot)
Set objRoot = Nothing
Set GetPsychometricsXML = objXML
Set objXML = Nothing
End Function
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.IXMLDOMProcessingIn
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.createProcessingIns
objXML.appendChild (objPI) '<< ERROR HERE!!!
Set objPI = Nothing
'// CREATE our ROOT NodeSet <RetrievePsychometricsRS />
Set objRoot = objXML.createNode(NODE_ELE
'// CREATE the Experiences NodeSet <Experiences />
objXML.appendChild (objRoot)
Set objRoot = Nothing
Set GetPsychometricsXML = objXML
Set objXML = Nothing
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
VB stuck those brackets in for me!!! It won't let me do it without them?
ASKER
As usual, top marks...
If I wanted to add nodes within say the RetrievePsychometricsRS node, could I use:
.selectSingleNode("Retriev ePsychomet ricsRS").a ppendChild .createElement("Something" )
If I wanted to add nodes within say the RetrievePsychometricsRS node, could I use:
.selectSingleNode("Retriev
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 =)
Anyways, try out the code I have posted =)
better is this
.documentElement.appendChi ld .createElement("Hello")
.documentElement.appendChi
ASKER
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 .createProcessingInstructi on("xml", " version=""1.0""")
.appendChild .createElement("RetrievePs ychometric sRS")
.documentElement.appendChi ld .createElement("Experience s")
.documentElement.appendChi ld .createElement("WorkingSty les")
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.firstChil d.appendCh ild .createElement("NoOfItems" )
And then I have to add a value to this! I think it could get out of control pretty quickly!
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 .createProcessingInstructi
.appendChild .createElement("RetrievePs
.documentElement.appendChi
.documentElement.appendChi
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.firstChil
And then I have to add a value to this! I think it could get out of control pretty quickly!
objXML.appendChild objPI