Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 11th, 2010, 05: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>
 
Old August 11th, 2010, 06:13 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 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
 
Old August 11th, 2010, 06: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.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Missing borders on a empty string field ProfGerdes Crystal Reports 1 March 15th, 2012 03: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 09:03 AM
detecting a form nfontaine Javascript How-To 2 April 20th, 2004 06:53 AM
Detecting Read-Only rgerald Access VBA 6 October 30th, 2003 04:51 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.