Solved

Check if XML node exists

Posted on 2010-11-15
3
1,166 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 46

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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Six Sigma Control Plans

622 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