Solved

Check if XML node exists

Posted on 2010-11-15
3
1,100 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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks for pointing me in the right direction.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

A short article about problems I had with the new location API and permissions in Marshmallow
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

772 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

10 Experts available now in Live!

Get 1:1 Help Now