[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Read attribute with msxml 4.0

Posted on 2004-03-24
9
Medium Priority
?
604 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 320 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 180 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

650 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