Solved

Read attribute with msxml 4.0

Posted on 2004-03-24
9
586 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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
 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…

828 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