Solved

Reading XML

Posted on 2006-11-20
6
222 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

831 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