How to detect a null child element?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thelouvre
    New Member
    • Feb 2010
    • 12

    How to detect a null child element?

    I want to do an sql query and if it returns EOF then I want to skip the append child step.
    Code:
    Set xmldom = New DOMDocument60
        
        xmldom.async = False
        xmldom.validateOnParse = False
        xmldom.resolveExternals = False
        xmldom.preserveWhiteSpace = True
        
            ' Create a processing instruction targeted for xml.
        Set Node = xmldom.createProcessingInstruction("xml", "version='1.0'")
        xmldom.appendChild Node
        Set Node = Nothing
        
        ' Create a processing instruction targeted for xml-stylesheet.
        'Set Node = dom.createProcessingInstruction("xml-stylesheet", _
                                    "type='text/xml' href='test.xsl'")
        'dom.appendChild Node
        'Set Node = Nothing
        
        ' Create a comment for the document.
        Set Node = xmldom.createComment("xml file created using 2.5.3 Software.")
        xmldom.appendChild Node
        Set Node = Nothing
        xmldom.createTextNode (vbNewLine + vbTab)
        ' Create the root element.
    
        Set root = xmldom.createElement(xmlPrefix + "LobbyReg")
        ' Create an attribute for the root element to define the schema
        Set attr = xmldom.createAttribute("xsi:schemaLocation")
        attr.Value = "file:///C:/XML LobbReg.xsd"
        root.setAttributeNode attr
        Set attr = Nothing
        ' Create an attribute for the root element to locate the schema
        Set attr = xmldom.createAttribute("xmlns:xsd")
        attr.Value = "file:///C:/XML"
        root.setAttributeNode attr
        Set attr = Nothing
        ' Create an attribute for the root element to ??schema??
        Set attr = xmldom.createAttribute("xmlns:xsi")
        attr.Value = "http://www.w3.org/2001/XMLSchema-instance"
        root.setAttributeNode attr
        Set attr = Nothing
        root.appendChild xmldom.createTextNode(vbNewLine + vbTab)
        xmldom.appendChild root
        
        ' Create the children elements.
        root.appendChild createSSN(xmldom)
    The createSSN routine will do the query and may not have a child to append at the last line. Normally, createSSN returns via

    Code:
          Set createSSN = SSNNode
          rsSSN.Close
          rsFiler.Close
          Exit Function
    What can you return is rsSSN.EOF is true?
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    Why don't you set a temporary variable to the result of createSSN, and check if it's null?
    Not sure if I'm missing something here.

    You really need to post how you're running the SQL query; that is the important part.

    Comment

    • thelouvre
      New Member
      • Feb 2010
      • 12

      #3
      I tried to do
      Code:
      Set CreateSSN = Nothing
      Exit Function
      when my query returned eof but my calling function died with that as I recall.
      I think I tried this too and it failed:
      Code:
      Set SSNnode = Nothing
      CreateSSN = SSNnode
      Exit Function

      Comment

      • jkmyoung
        Recognized Expert Top Contributor
        • Mar 2006
        • 2057

        #4
        Where are you running the query? How?

        Comment

        • thelouvre
          New Member
          • Feb 2010
          • 12

          #5
          my code was like this
          Code:
              strsql = "Select * From cvrSSN Where REPNO = " + "'" + gsRepno + "'"
              rsSSN.Open strsql, cn, adOpenForwardOnly, adLockReadOnly
              '!!check for no records and exit without child elements
              If rsSSN.EOF Then

          Comment

          • thelouvre
            New Member
            • Feb 2010
            • 12

            #6
            oh and that code was in createSSN function.

            I tried all sorts of ways to try to return "Nothing".. .
            I either got invalid use of object or when I tried to check for Nothing in the calling routine, or invalid procedure call or argument in the function being called.

            Comment

            • jkmyoung
              Recognized Expert Top Contributor
              • Mar 2006
              • 2057

              #7
              try
              if rsSSN.RecordCou nt == 0

              Comment

              Working...