Solved

Read attribute with msxml 4.0

Posted on 2004-03-24
9
579 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
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.

 

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

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

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

932 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

15 Experts available now in Live!

Get 1:1 Help Now