Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Check if XML node exists

Posted on 2010-11-15
3
Medium Priority
?
1,178 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 1500 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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

Make the most of your online learning experience.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
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 …
Six Sigma Control Plans

670 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