Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP XML
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Classic ASP XML Using ASP 3 and XML. See also the XML category for more XML discussions not relating to ASP. NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP XML section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old August 11th, 2010, 06:40 AM
Registered User
 
Join Date: Aug 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Detecting empty or missing nodes

I'm parsing XMl with Microsoft.XMLDOM. My problem is sometimes a node is empty or missing (when exporting XML from Excel) and I get an error.
So, how do I test for teh existance of a named node and whether it is empty or not?
Example below is missing para2 node (because it was empty). However if the client edited the XML in notepad, a node might exist thus <subhead></subhead>


<news>
<headline>AlphaWireless to exhibit at 4GWorld in Chicago</headline>
<subhead> Oct 19-21, 2010</subhead>
<para1>See us on stand 106. See http://4gworld.com for details.</para1>
<subdate>10/08/2010</subdate>
<expiredate>01/11/2010</expiredate>
<ID>2</ID>
</news>
Reply With Quote
  #2 (permalink)  
Old August 11th, 2010, 07:13 AM
Friend of Wrox
Points: 6,438, Level: 34
Points: 6,438, Level: 34 Points: 6,438, Level: 34 Points: 6,438, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,196
Thanks: 0
Thanked 237 Times in 236 Posts
Default

Code:
Dim doc
Set doc = CreateObject("Msxml2.DOMDocument.3.0")
doc.async = False
If doc.load(Server.MapPath("file.xml")) Then
  doc.setProperty "SelectionLanguage", "XPath"
  Set para2El = doc.selectSingleNode("news/para2")
  If para2El Is Nothing Then
    ' element does not exist, handle that here
  Else
    ' element does exist
    If para2El.hasChildNodes() Then
      ' para2El is not empty
    End If
  End If
End If
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
Reply With Quote
  #3 (permalink)  
Old August 11th, 2010, 07:44 AM
Registered User
 
Join Date: Aug 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Excellent. So hard to find that info online, everyone assumes all xml nodes present.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Missing borders on a empty string field ProfGerdes Crystal Reports 1 March 15th, 2012 04:14 PM
Test for empty nodes, including only whitespace mphare XSLT 2 December 17th, 2008 03:40 PM
Counting Nodes That Are Not Empty tommyready XSLT 2 September 4th, 2007 10:03 AM
detecting a form nfontaine Javascript How-To 2 April 20th, 2004 07:53 AM
Detecting Read-Only rgerald Access VBA 6 October 30th, 2003 04:51 PM



All times are GMT -4. The time now is 07:05 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.