Solved

Reading XML

Posted on 2006-11-20
6
209 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
Comment Utility
n.Attributes.getNamedItem("value").Text
0
 
LVL 10

Author Comment

by:Clif
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 10

Author Comment

by:Clif
Comment Utility
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]
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

763 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

13 Experts available now in Live!

Get 1:1 Help Now