1

Given the following XML, how would I check to see if a particular node is empty. For instance the <sale_price></sale_price>.

What I am trying to do is have a if statement that will run some code if the node is empty or skip it if it is not.

<?xml version="1.0" encoding="iso-8859-1"?>
    <Export>
        <SAVED_EXPORT>
             <id>00-6189</id>
             <price>5.46 USD</price>
             <sale_price></sale_price>
         </SAVED_EXPORT>
    </Export>
2
  • What code do you have so far? Or do you, besides the "node empty" check, also want how to load/parse/query an XML file in VBScript but were afraid to ask? ;) Commented Oct 19, 2011 at 7:12
  • No, I have the code to load and parse but I didn't want to give more information that needed making any potential help less likely and certainly more difficult and confusing. Commented Oct 19, 2011 at 11:43

1 Answer 1

3
Set oNode=oXML.selectSingleNode("//Export/SAVED_EXPORT/sale_price/")
If not(oNode is nothing) then 
   If oNode.Text="" Then

   End If
End If
Sign up to request clarification or add additional context in comments.

4 Comments

The XPath to check the node for text contents would be //Export/SAVED_EXPORT/sale_price[normalize-space() != ''], otherwise the code is fine. If you omit the XPath test, you might get back a node and would have to check for both Nothing and Trim(oNode.nodeValue) = "" in the VBscript code.
While this probably works, for some reason in my code it is not working. I will have to re-ask my question but next time provide the full code and narrow the scope of the question down to the specific issue I am having. THX
It's not too late to clarify the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.