Solved

Read attribute with msxml 4.0

Posted on 2004-03-24
9
575 Views
Last Modified: 2011-09-20
Hello

This works in msxml 3:

      Set ElemList = objXMLin.getElementsByTagname("head")
      ElemList.item(0).attributes.getNamedItem("date.publication").nodeValue

But it doesn't work in msxml 4. What would be the equivalent to the above in msxml 4?

My xml looks somthing like this:

 <head>
  <pubdata date.publication="20040318T00:00:00-0000" edition.name="1udg" issue="Ost" name="EB" number="" position.section="1" position.sequence="2" volume="" />
 </head>
0
Comment
Question by:speder
  • 4
  • 3
  • 2
9 Comments
 
LVL 26

Expert Comment

by:EDDYKT
ID: 10668605
Should it be

Set ElemList = objXMLin.getElementsByTagName("head/pubdata")
Debug.Print ElemList.Item(0).Attributes.getNamedItem("date.publication").Text
0
 
LVL 26

Accepted Solution

by:
Rejojohny earned 80 total points
ID: 10668615
try this ...

ElemList.item(0).childNodes(0).attributes.getNamedItem("date.publication").nodeValue  


0
 
LVL 26

Expert Comment

by:Rejojohny
ID: 10668632
i am not very sure how ur code worked even on xml 3 as
Set ElemList = objXMLin.getElementsByTagname("head")
gives back a nodelist "<head>"

so the first child is the node that u want ... the above code might not have worked for xml3 too .. thats my opnion ..
0
 

Author Comment

by:speder
ID: 10668739
Sorry, it should have said:

Set ElemList = objXMLin.getElementsByTagName("head/pubdata")

As EDDYKT write, but unfortunately it still throws a:

This name may not contain a '/' character

head-->/<--pubdata
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:speder
ID: 10668767
Now, I tried both:

      Set ElemList = objXMLin.getElementsByTagname("head")
      ElemList.item(0).childNodes(0).attributes.getNamedItem("date.publication").nodeValue

And

      Set ElemList = objXMLin.getElementsByTagname("head/pubdata")
      ElemList.item(0).attributes.getNamedItem("date.publication").nodeValue

Both throw the "name may not contain a '/' character error.
0
 
LVL 26

Expert Comment

by:Rejojohny
ID: 10668795
but in the first option .. there is no "/" in ur name . then how can u get the same error ...

unfortunately .. i do not have xml4 .. so cannot test it ..
0
 

Author Comment

by:speder
ID: 10668886
You're right, but:

Set ElemList = objXMLin.getElementsByTagname("head")
ElemList.item(0).childNodes(0).attributes.getNamedItem("date.publication").nodeValue  

Throws a "object required getNamedItem(...)"

0
 
LVL 26

Assisted Solution

by:EDDYKT
EDDYKT earned 45 total points
ID: 10669083
Strange, it works on my VB

Where do you call from?

What is objXMLin?
0
 

Author Comment

by:speder
ID: 10671541
Here's my example. If I use MSXML 3 it's working fine. If I use MSXML 4 it throws the "may not contain..."-error.

Dim objXMLin
Set objXMLin = CreateObject("Msxml2.DOMDocument.4.0")
'Set objXMLin = CreateObject("Microsoft.XMLDOM")
objXMLin.async = False

objXMLin.loadXML("<head><pubdata date.publication='whatever' /></head>")

If objXMLin.parseError <> 0 Then
      MsgBox objXMLin.parseError.reason
End If

Set ElemList = objXMLin.getElementsByTagname("head/pubdata")

MsgBox ElemList.item(0).attributes.getNamedItem("date.publication").nodeValue
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

707 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