• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 608
  • Last Modified:

Read attribute with msxml 4.0

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
speder
Asked:
speder
  • 4
  • 3
  • 2
2 Solutions
 
EDDYKTCommented:
Should it be

Set ElemList = objXMLin.getElementsByTagName("head/pubdata")
Debug.Print ElemList.Item(0).Attributes.getNamedItem("date.publication").Text
0
 
RejojohnyCommented:
try this ...

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


0
 
RejojohnyCommented:
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.

 
spederAuthor Commented:
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
 
spederAuthor Commented:
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
 
RejojohnyCommented:
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
 
spederAuthor Commented:
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
 
EDDYKTCommented:
Strange, it works on my VB

Where do you call from?

What is objXMLin?
0
 
spederAuthor Commented:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now