Solved

Reading XML

Posted on 2006-11-20
6
216 Views
Last Modified: 2013-11-19
I am reading an XML file through the MSXML2.IXMLDOMNode.

Partof my XML looks something like this:

   <UseDefaultAddressFlag value="Yes"/>

I can't seem to find any attribute of IXMLDOMNode that will retrieve the value ("Yes", in the above case)

How do I retrieve the value?
0
Comment
Question by:Clif
  • 4
  • 2
6 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 125 total points
ID: 17979695
n.Attributes.getNamedItem("value").Text
0
 
LVL 10

Author Comment

by:Clif
ID: 17979789
That gives me an "Object variable or With block variable not set:

Works:
Debug.Print "> " & objNode.nodeName & " - (" & objNode.Text & ")"

Errors:
Debug.Print "> " & objNode.nodeName & " - (" & objNode.Text & ") - <" & objNode.Attributes.getNamedItem("value").Text & ">"

(In both above cases objNode has been set to MSXML2.IXMLDOMNode, I am using the Microsoft XML v4.0 library))
0
 
LVL 10

Author Comment

by:Clif
ID: 17980320
I discovered why I was getting the error.

Some tags do not have a value attribute.  So, is there a way (aside from "On Error Resume Next") to not cause an error when I run across tags that don't have a "value" attribute?
0
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.

 
LVL 10

Author Comment

by:Clif
ID: 17980418
I went ahead and accepted the answer because it was the correct answer.

If you can answer the second question, more's the better.  :)
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17994290
Glad I could help, sorry for the late response (i got my emails from EE with up to 3 days of delay :-(

>So, is there a way (aside from "On Error Resume Next") to not cause an error when I run across tags that don't have a "value" attribute?
I have not seen a function to return that information, but you could of course loop on the attributes collection to find the one you are looking for.
however, if there will be alot of attributes in general, that method will cost alot more time than the ON ERROR methods...
0
 
LVL 10

Author Comment

by:Clif
ID: 17995143
Thanks.

On Error will work, of course, but it's never the preferrred solution.  Looping through the attributes to find out if the one I want is there would be more unneccesary coding than on On Error would be, so I'll stick with that.
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

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

867 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