Solved

Check if XML node exists

Posted on 2010-11-15
3
1,160 Views
Last Modified: 2012-05-10
Hi,

I am trying to create a script that returns scheduled days and times.

        Set objXML = CreateObject("Microsoft.XMLDOM")
        Set objLst = CreateObject("Microsoft.XMLDOM")
        objXML.async = False
 
        Dim objNodeList
        Dim objNode
        Dim objSubNode
 
        objXML.LoadXML (BackupJobs)
        Set objLst = objXML.getElementsByTagName("*")
        Set objNodeList = objXML.SelectNodes("*")

I need something like:

for each Node in Nodelist
  If node.Name = "Daily" then
      Do stuff
  elseif node.Name = "Weeky" then
   Do other stuff
  end if

Hope this is clear enough.

<Set ID="MyID123" Name="MyData"> 
<Loc>D:\A</SelectedSource>
<Loc>D:\B</SelectedSource>
<Loc>D:\C</SelectedSource>
<Loc>D:\D</SelectedSource>

<Daily ID="Daily123" Name="Schedule1" Hour="0" Minute="0"/>
<Weekly ID="Weekly123" Sun="N" Mon="N" Tue="N" Wed="N" Thu="N" Fri="N" Sat="N" Hour="" Minute="" Duration="" 

BackupType=""/>

<RetentionPolicy Unit="DAYS" Period="7"></RetentionPolicy>

<ExtraLocalBackup ENABLED="N" Zip="Y" BackupTo="C:\LocalBackup" SkipOffsiteBackup="N" SetLocalCopyPermission="Y"/>

Open in new window

0
Comment
Question by:patlan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 13

Accepted Solution

by:
gbanik earned 500 total points
ID: 34144716
First your XML file is malformed... what it means is, it not a valid XML file. An XML file has to have proper opening and closing tags. Start the XML file with a <?xml version=""1.0"" encoding=""ISO-8859-1""?>. Have a root tag like <DATA></DATA>, and all your contents would come between the <DATA>...</DATA>.

Second, here is a good link for you to study how XML files are parsed.
http://msdn.microsoft.com/en-us/library/aa163921(office.10).aspx

XML parsing actually is pretty easy once u get the hang of it.

ps. Just in case u dont get it, here is a sample project
http://www.freevbcode.com/ShowCode.asp?ID=5750

Still need more help....
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_23015675.html 
See accepted comment ID:20450875
0
 
LVL 45

Expert Comment

by:aikimark
ID: 34145073
To expand on the gbanik comment...
1. Your node tags are not matched
<Loc>D:\A</SelectedSource>

should be
<Loc>D:\A</Loc>

or
<SelectedSource>D:\A</SelectedSource>

=============
You might want to download the free Microsoft tool, XMLNotepad.  It will help you edit and save correctly formed XML files.
0
 

Author Closing Comment

by:patlan
ID: 34407055
Thanks for pointing me in the right direction.
0

Featured Post

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an explanation of a simple data model to help parse a JSON feed
In this post we will learn different types of Android Layout and some basics of an Android App.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question