Solved

Check if XML node exists

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
oracle query help 18 99
Please explain: Aspect Oriented Programming 2 84
SUM 2 INTEGER ARRAYS INTO 1 10 93
Run a .bat file wich is inside a .vbs file 8 24
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
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 …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now