xmlDoc.getElementsByTagName PROBLEM WITH NULL Values

arkadis

Registered User.
Local time
Today, 10:59
Joined
Dec 3, 2015
Messages
16
Hey guys i'm attaching a SOAP request/response i'm working with.
Code breaks when xml TAG is missing at the end of my code. How can i manage this problem with NULL values????

Code:
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.SetProperty "SelectionLanguage", "XPath"
xmlDoc.async = False
                    With CreateObject("MSXML2.XMLHTTP")
                        xmlDoc.loadXML (get_akciz_codes)
                    End With
                            Set nID = xmlDoc.getElementsByTagName("ID")
                            Set nTitle = xmlDoc.getElementsByTagName("TITLE")
                            Set nMEASURMENT = xmlDoc.getElementsByTagName("MEASURMENT")
                            Set nSAKON_KODI = xmlDoc.getElementsByTagName("SAKON_KODI")
                            Set nAKCIS_GANAKV = xmlDoc.getElementsByTagName("AKCIS_GANAKV")
                                Dim Resp As String
                                For i = 0 To nID.Length - 1
                                    rID = nID(i).TEXT
                                    rTitle = nTitle(i).TEXT
                                   [COLOR="Red"][B] rMEASURMENT = nMEASURMENT(i).TEXT[/B][/COLOR] 'Not available always
                                    rSAKON_KODI = nSAKON_KODI(i).TEXT
                                    rAKCIS_GANAKV = nAKCIS_GANAKV(i).TEXT
                                Next
End Function
 
if it is supposed to return a number yes - if text the change 0 to ""
 
if it is supposed to return a number yes - if text the change 0 to ""

It does't seem to like this.
I Receive an error 450 -> wrong number of arguments or invalid property assignment
When i post it like this->
Set nMEASUREMENT = Nz(xmlDoc.getElementsByTagName("MEASUREMENT"), "")
Or
Set nMEASUREMENT = Nz(xmlDoc.getElementsByTagName("MEASUREMENT"), 0)
 
in that case it may be because the I is out of range - put some code in to check the number of elements in measurements and if I is out of range assign a 0 or "" as required
 
In recent times, I have been having more situations where data has to be imported from xml files generated by user input into web pages. I have been bitten too many times by lack of validity testing at the web end, that I now mostly import all data into text fields so I can control the validity testing.

For example, where the Access table had a numeric field for number of participants (for client requirement to do numeric averages), the web form would accept "50 to 100".

I handle null values by
txtData = xmlDoc.getElementsByTagName("whatever") & ""
 
In recent times, I have been having more situations where data has to be imported from xml files generated by user input into web pages. I have been bitten too many times by lack of validity testing at the web end, that I now mostly import all data into text fields so I can control the validity testing.

For example, where the Access table had a numeric field for number of participants (for client requirement to do numeric averages), the web form would accept "50 to 100".

I handle null values by
txtData = xmlDoc.getElementsByTagName("whatever") & ""

It does't seem to like this.
Untitled.jpg
 
Your initial post had this line

rMEASURMENT = nMEASURMENT(i).TEXT

Is nMEASURMENT DIMmed as an array or not?
 
Your initial post had this line

rMEASURMENT = nMEASURMENT(i).TEXT

Is nMEASURMENT DIMmed as an array or not?

No it is not. Actual i trying to find a way to create array list from this xml response.
Untitled.jpg
 
So are you saying that your issue is not with tags having no data (title of thread) but how to process child nodes?

My xml skills are limited. Maybe you should start a new thread with a more appropriate title, or check out a site focussed more on processing xml.
 
So are you saying that your issue is not with tags having no data (title of thread) but how to process child nodes?

My xml skills are limited. Maybe you should start a new thread with a more appropriate title, or check out a site focussed more on processing xml.

No i am working on both issues.
1) tags having no data
2) process child nodes to create ado (in memory) temporary recordset
 
Finally!

In order to avoid problems with missing nodes we need the following code!
A function in a module:
Code:
Public Function xNothingNode(varN As Variant)
If varN Is Nothing Then
    xNothingNode = 0
Else
    xNothingNode = varN.TEXT
End If
End Function

And this is how we use the function in our code:
Code:
Set sInvoice = node.selectSingleNode("INVOICE_ID")
sInv = xNothingNode(sInvoice)
 

Users who are viewing this thread

Back
Top Bottom