huixu01
asked on
How can I get the attribute value?
I have one asp page, inside this page I want to parse a xml file, I want to get the value of attrbutes of nodes. I know this works in vb component, Node.childnodes(i).attribu tes.getNam eItem("nam e").text, but it doesn't work in asp. I want to know the proper syntex.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Here is a class module I use to manipulate XML, For your purpose look at the "EditItem" Function.
Enjoy!
Option Explicit
'Private XML holders
Private m_ActiveNode As IXMLDOMNode
Const UserLNK As String = "Markup.xml"
Const UserFile As String = "User.xib"
'Private Data Members
Private m_BOF As Boolean
Private m_EOF As Boolean
Private m_ImgID As String
Private m_Line As Long
Private m_Offset As Long
Private m_Length As Long
Private m_Address As String
Private m_Filename As String
Private m_isModified As Boolean
Private m_Error As Long
Private m_szError As String
Private m_UserLnkFile As String
'Private Constants
Const SUCCESS As Boolean = True
Const FAIL As Boolean = Not SUCCESS
Public Property Get isModified() As Boolean
isModified = m_isModified
End Property
Public Property Let ImgID(ByVal newVal As String)
m_ImgID = newVal
End Property
Public Property Get ImgID() As String
ImgID = m_ActiveNode.Attributes.ge tNamedItem ("ImgID"). Text
End Property
Public Property Let Offset(ByVal newVal As Long)
m_Offset = newVal
End Property
Public Property Get Offset() As Long
If (m_ActiveNode.Attributes.g etNamedIte m("Offset" ).Text) = "" Then
Offset = 0
Else
Offset = CLng(m_ActiveNode.Attribut es.getName dItem("Off set").Text )
End If
End Property
Public Property Let Length(ByVal newVal As Long)
m_Length = newVal
End Property
Public Property Get Length() As Long
If (m_ActiveNode.Attributes.g etNamedIte m("Length" ).Text) = "" Then
Length = 0
Else
Length = CLng(m_ActiveNode.Attribut es.getName dItem("Len gth").Text )
End If
End Property
Public Property Let Line(ByVal newVal As Long)
m_Line = newVal
End Property
Public Property Get Line() As Long
If (m_ActiveNode.Attributes.g etNamedIte m("Line"). Text) = "" Then
Line = 0
Else
Line = CLng(m_ActiveNode.Attribut es.getName dItem("Lin e").Text)
End If
End Property
Public Property Let Address(ByVal newVal As String)
m_Address = newVal
End Property
Public Property Get Address() As String
Address = m_ActiveNode.Attributes.ge tNamedItem ("Address" ).Text
End Property
Private Property Let EOF(ByVal newVal As Boolean)
m_EOF = newVal
End Property
Public Property Get EOF() As Boolean
EOF = m_EOF
End Property
Private Property Let BOF(ByVal newVal As Boolean)
m_BOF = newVal
End Property
Public Property Get BOF() As Boolean
BOF = m_BOF
End Property
Public Property Get FullPath() As String
FullPath = GetTempPath() + UserFile
End Property
Public Property Get fileName() As String
fileName = m_Filename
End Property
Public Property Get Error() As Long
Error = m_Error
End Property
Public Property Get ErrorDesc() As String
ErrorDesc = m_szError
End Property
Public Sub MoveFirst()
Set m_ActiveNode = m_XML_DOM.selectSingleNode ("Markup/H yperLinks/ Link")
If Not m_ActiveNode Is Nothing Then
m_BOF = True
m_EOF = False
Else
m_EOF = True
End If
End Sub
Public Sub MoveLast()
If Not m_ActiveNode.lastChild Is Nothing Then
Set m_ActiveNode = m_ActiveNode.lastChild
End If
m_EOF = True
m_BOF = False
End Sub
Public Sub MoveNext()
If Not m_ActiveNode.nextSibling Is Nothing Then
Set m_ActiveNode = m_ActiveNode.nextSibling
Else
m_EOF = True
End If
End Sub
Public Sub MovePrev()
If Not m_ActiveNode.previousSibli ng Is Nothing Then
Set m_ActiveNode = m_ActiveNode.previousSibli ng
Else
m_BOF = True
End If
End Sub
Private Function SearchItem(nLine As Long, nOffset As Long) As IXMLDOMNode
Set SearchItem = m_XML_DOM.selectSingleNode ("Markup/H yperLinks/ Link[@Line $eq$ " & nLine & "][@Offset
$eq$ " & nOffset & "]")
End Function
Public Function SetItem(nLineNo As Long, nOffset As Long) As Boolean
SetItem = FAIL
Set m_ActiveNode = m_XML_DOM.selectSingleNode ("Markup/H yperLinks/ Link[@Line $eq$ " & nLineNo & "][@Offset
$eq$ " & nOffset & "]")
If Not m_ActiveNode Is Nothing Then SetItem = SUCCESS
End Function
Public Function AddItem() As Boolean
On Error GoTo EH
AddItem = FAIL
Dim oRoot As IXMLDOMNode
Dim oNode As IXMLDOMNode
Dim oChild As IXMLDOMNode
Dim oAttrib As IXMLDOMAttribute
If m_XML_DOM Is Nothing Then
Set m_XML_DOM = New DOMDocument
'
' New Document, add headings
'
Set oNode = m_XML_DOM.createProcessing Instructio n("xml", "version='1.0'")
Set oNode = m_XML_DOM.insertBefore(oNo de, m_XML_DOM.childNodes.Item( 0))
'
' Create document roots
'
Set oRoot = m_XML_DOM.createElement("M arkup")
Set m_XML_DOM.documentElement = oRoot
Set oChild = m_XML_DOM.createElement("H yperLinks" )
oRoot.appendChild oChild
End If
Set oRoot = m_XML_DOM.selectSingleNode ("Markup")
Set oChild = oRoot.selectSingleNode("Hy perLinks")
'
' Set the root document element to be appended to.
'
Set oRoot = m_XML_DOM.selectSingleNode ("Markup/H yperLinks" )
'
' add item
'
Set oNode = m_XML_DOM.createElement("L ink")
oRoot.appendChild oNode
'
' set node attributes
'
Set oAttrib = m_XML_DOM.createAttribute( "Line")
oAttrib.Text = m_Line
oNode.Attributes.setNamedI tem oAttrib
Set oAttrib = m_XML_DOM.createAttribute( "Offset")
oAttrib.Text = m_Offset
oNode.Attributes.setNamedI tem oAttrib
Set oAttrib = m_XML_DOM.createAttribute( "Length")
oAttrib.Text = m_Length
oNode.Attributes.setNamedI tem oAttrib
Set oAttrib = m_XML_DOM.createAttribute( "ImgID")
oAttrib.Text = m_ImgID
oNode.Attributes.setNamedI tem oAttrib
Set oAttrib = m_XML_DOM.createAttribute( "Address")
oAttrib.Text = m_Address
oNode.Attributes.setNamedI tem oAttrib
m_isModified = True
AddItem = SUCCESS
Set oRoot = Nothing
Set oNode = Nothing
Set oChild = Nothing
Set oAttrib = Nothing
Exit Function
EH:
ProcessError
End Function
Public Function RemoveItem(nLineNo As Long, nOffset As Long) As Boolean
On Error GoTo EH:
RemoveItem = FAIL
Dim oNode As IXMLDOMNode
Dim oChild As IXMLDOMNode
Set oNode = m_XML_DOM.selectSingleNode ("Markup/H yperLinks" )
Set oChild = SearchItem(nLineNo, nOffset)
If Not oChild Is Nothing Then
oNode.removeChild oChild
RemoveItem = SUCCESS
m_isModified = True
End If
Set oNode = Nothing
Set oChild = Nothing
Exit Function
EH:
ProcessError
End Function
Public Function EditItem(nLineNo As Long, nOffset As Long) As Boolean
On Error GoTo EH:
EditItem = FAIL
Const EditAddr As Byte = 1
Dim oNode As IXMLDOMNode
Dim oChild As IXMLDOMNode
Dim oUpdateChild As IXMLDOMNode
Set oNode = m_XML_DOM.selectSingleNode ("Markup/H yperLinks" )
'
' set desired node
'
Set oChild = SearchItem(nLineNo, nOffset)
If Not oChild Is Nothing Then
'
' copy old child to child to be updated
'
Set oUpdateChild = oChild
With oUpdateChild.Attributes
If .getNamedItem("ImgID").Tex t <> "" And .getNamedItem("Address").T ext <> "" Then
Dim strTemp As String
Dim strFileOnly As String
strTemp = .getNamedItem("Address").T ext
'
' check for web address
'
If InStr(1, strTemp, "http://") = 0 Then
'
' check for local file
'
If InStr(2, strTemp, ":\") Then
'
' local file, remove the file location
'
strFileOnly = StripPath(strTemp)
'
' change address value
'
.getNamedItem("Address").T ext = strFileOnly
End If
End If
End If
End With
'
' replace old node with updates
'
oNode.replaceChild oUpdateChild, oChild
EditItem = SUCCESS
End If
Set oNode = Nothing
Set oChild = Nothing
Set oUpdateChild = Nothing
Exit Function
EH:
MsgBox Err.Number & Err.Description
ProcessError
End Function
Public Function Load(ByVal szFileName As String) As Boolean
Load = FAIL
'
' Capture VDF File name
'
m_Filename = szFileName
Set m_XML_DOM = New DOMDocument
m_XML_DOM.async = False
'
' open XML document
'
If (m_XML_DOM.Load(m_UserLnkF ile)) Then
'
' seek to desired element
'
Dim oParent As IXMLDOMNode
Set oParent = m_XML_DOM.selectSingleNode ("Markup/H yperLinks" )
If Not oParent Is Nothing Then Load = SUCCESS
Set oParent = Nothing
Else
ProcessError
End If
End Function
Public Function Save(szVDFFile As String) As Boolean
Dim Zip As New CDynaZip
Dim XIBRead As New viVDFReader.VDFXib
Save = FAIL
MoveFirst
'
' Edit to remove temp file directory structure
'
Do While Not EOF
EditItem Line, Offset
MoveNext
Loop
'
' save XML file to temp directory
'
m_XML_DOM.Save m_UserLnkFile
'
' zip file into a file called user.xib
'
If (Zip.AddFile(FullPath, m_UserLnkFile)) Then
'
' save user.xib to the VDF file
'
Save = XIBRead.SaveToZipFile(szVD FFile, FullPath)
End If
End Function
Private Sub ProcessError()
On Error Resume Next
Dim Error As IXMLDOMParseError
Set Error = m_XML_DOM.parseError
m_Error = Error.ErrorCode
m_szError = Error.reason + "Line: " + CStr(Error.Line)
Set Error = Nothing
End Sub
Private Sub Class_Initialize()
m_UserLnkFile = GetTempPath() + UserLNK
End Sub
Private Sub Class_Terminate()
Set m_XML_DOM = Nothing
Set m_ActiveNode = Nothing
End Sub
Enjoy!
Option Explicit
'Private XML holders
Private m_ActiveNode As IXMLDOMNode
Const UserLNK As String = "Markup.xml"
Const UserFile As String = "User.xib"
'Private Data Members
Private m_BOF As Boolean
Private m_EOF As Boolean
Private m_ImgID As String
Private m_Line As Long
Private m_Offset As Long
Private m_Length As Long
Private m_Address As String
Private m_Filename As String
Private m_isModified As Boolean
Private m_Error As Long
Private m_szError As String
Private m_UserLnkFile As String
'Private Constants
Const SUCCESS As Boolean = True
Const FAIL As Boolean = Not SUCCESS
Public Property Get isModified() As Boolean
isModified = m_isModified
End Property
Public Property Let ImgID(ByVal newVal As String)
m_ImgID = newVal
End Property
Public Property Get ImgID() As String
ImgID = m_ActiveNode.Attributes.ge
End Property
Public Property Let Offset(ByVal newVal As Long)
m_Offset = newVal
End Property
Public Property Get Offset() As Long
If (m_ActiveNode.Attributes.g
Offset = 0
Else
Offset = CLng(m_ActiveNode.Attribut
End If
End Property
Public Property Let Length(ByVal newVal As Long)
m_Length = newVal
End Property
Public Property Get Length() As Long
If (m_ActiveNode.Attributes.g
Length = 0
Else
Length = CLng(m_ActiveNode.Attribut
End If
End Property
Public Property Let Line(ByVal newVal As Long)
m_Line = newVal
End Property
Public Property Get Line() As Long
If (m_ActiveNode.Attributes.g
Line = 0
Else
Line = CLng(m_ActiveNode.Attribut
End If
End Property
Public Property Let Address(ByVal newVal As String)
m_Address = newVal
End Property
Public Property Get Address() As String
Address = m_ActiveNode.Attributes.ge
End Property
Private Property Let EOF(ByVal newVal As Boolean)
m_EOF = newVal
End Property
Public Property Get EOF() As Boolean
EOF = m_EOF
End Property
Private Property Let BOF(ByVal newVal As Boolean)
m_BOF = newVal
End Property
Public Property Get BOF() As Boolean
BOF = m_BOF
End Property
Public Property Get FullPath() As String
FullPath = GetTempPath() + UserFile
End Property
Public Property Get fileName() As String
fileName = m_Filename
End Property
Public Property Get Error() As Long
Error = m_Error
End Property
Public Property Get ErrorDesc() As String
ErrorDesc = m_szError
End Property
Public Sub MoveFirst()
Set m_ActiveNode = m_XML_DOM.selectSingleNode
If Not m_ActiveNode Is Nothing Then
m_BOF = True
m_EOF = False
Else
m_EOF = True
End If
End Sub
Public Sub MoveLast()
If Not m_ActiveNode.lastChild Is Nothing Then
Set m_ActiveNode = m_ActiveNode.lastChild
End If
m_EOF = True
m_BOF = False
End Sub
Public Sub MoveNext()
If Not m_ActiveNode.nextSibling Is Nothing Then
Set m_ActiveNode = m_ActiveNode.nextSibling
Else
m_EOF = True
End If
End Sub
Public Sub MovePrev()
If Not m_ActiveNode.previousSibli
Set m_ActiveNode = m_ActiveNode.previousSibli
Else
m_BOF = True
End If
End Sub
Private Function SearchItem(nLine As Long, nOffset As Long) As IXMLDOMNode
Set SearchItem = m_XML_DOM.selectSingleNode
$eq$ " & nOffset & "]")
End Function
Public Function SetItem(nLineNo As Long, nOffset As Long) As Boolean
SetItem = FAIL
Set m_ActiveNode = m_XML_DOM.selectSingleNode
$eq$ " & nOffset & "]")
If Not m_ActiveNode Is Nothing Then SetItem = SUCCESS
End Function
Public Function AddItem() As Boolean
On Error GoTo EH
AddItem = FAIL
Dim oRoot As IXMLDOMNode
Dim oNode As IXMLDOMNode
Dim oChild As IXMLDOMNode
Dim oAttrib As IXMLDOMAttribute
If m_XML_DOM Is Nothing Then
Set m_XML_DOM = New DOMDocument
'
' New Document, add headings
'
Set oNode = m_XML_DOM.createProcessing
Set oNode = m_XML_DOM.insertBefore(oNo
'
' Create document roots
'
Set oRoot = m_XML_DOM.createElement("M
Set m_XML_DOM.documentElement = oRoot
Set oChild = m_XML_DOM.createElement("H
oRoot.appendChild oChild
End If
Set oRoot = m_XML_DOM.selectSingleNode
Set oChild = oRoot.selectSingleNode("Hy
'
' Set the root document element to be appended to.
'
Set oRoot = m_XML_DOM.selectSingleNode
'
' add item
'
Set oNode = m_XML_DOM.createElement("L
oRoot.appendChild oNode
'
' set node attributes
'
Set oAttrib = m_XML_DOM.createAttribute(
oAttrib.Text = m_Line
oNode.Attributes.setNamedI
Set oAttrib = m_XML_DOM.createAttribute(
oAttrib.Text = m_Offset
oNode.Attributes.setNamedI
Set oAttrib = m_XML_DOM.createAttribute(
oAttrib.Text = m_Length
oNode.Attributes.setNamedI
Set oAttrib = m_XML_DOM.createAttribute(
oAttrib.Text = m_ImgID
oNode.Attributes.setNamedI
Set oAttrib = m_XML_DOM.createAttribute(
oAttrib.Text = m_Address
oNode.Attributes.setNamedI
m_isModified = True
AddItem = SUCCESS
Set oRoot = Nothing
Set oNode = Nothing
Set oChild = Nothing
Set oAttrib = Nothing
Exit Function
EH:
ProcessError
End Function
Public Function RemoveItem(nLineNo As Long, nOffset As Long) As Boolean
On Error GoTo EH:
RemoveItem = FAIL
Dim oNode As IXMLDOMNode
Dim oChild As IXMLDOMNode
Set oNode = m_XML_DOM.selectSingleNode
Set oChild = SearchItem(nLineNo, nOffset)
If Not oChild Is Nothing Then
oNode.removeChild oChild
RemoveItem = SUCCESS
m_isModified = True
End If
Set oNode = Nothing
Set oChild = Nothing
Exit Function
EH:
ProcessError
End Function
Public Function EditItem(nLineNo As Long, nOffset As Long) As Boolean
On Error GoTo EH:
EditItem = FAIL
Const EditAddr As Byte = 1
Dim oNode As IXMLDOMNode
Dim oChild As IXMLDOMNode
Dim oUpdateChild As IXMLDOMNode
Set oNode = m_XML_DOM.selectSingleNode
'
' set desired node
'
Set oChild = SearchItem(nLineNo, nOffset)
If Not oChild Is Nothing Then
'
' copy old child to child to be updated
'
Set oUpdateChild = oChild
With oUpdateChild.Attributes
If .getNamedItem("ImgID").Tex
Dim strTemp As String
Dim strFileOnly As String
strTemp = .getNamedItem("Address").T
'
' check for web address
'
If InStr(1, strTemp, "http://") = 0 Then
'
' check for local file
'
If InStr(2, strTemp, ":\") Then
'
' local file, remove the file location
'
strFileOnly = StripPath(strTemp)
'
' change address value
'
.getNamedItem("Address").T
End If
End If
End If
End With
'
' replace old node with updates
'
oNode.replaceChild oUpdateChild, oChild
EditItem = SUCCESS
End If
Set oNode = Nothing
Set oChild = Nothing
Set oUpdateChild = Nothing
Exit Function
EH:
MsgBox Err.Number & Err.Description
ProcessError
End Function
Public Function Load(ByVal szFileName As String) As Boolean
Load = FAIL
'
' Capture VDF File name
'
m_Filename = szFileName
Set m_XML_DOM = New DOMDocument
m_XML_DOM.async = False
'
' open XML document
'
If (m_XML_DOM.Load(m_UserLnkF
'
' seek to desired element
'
Dim oParent As IXMLDOMNode
Set oParent = m_XML_DOM.selectSingleNode
If Not oParent Is Nothing Then Load = SUCCESS
Set oParent = Nothing
Else
ProcessError
End If
End Function
Public Function Save(szVDFFile As String) As Boolean
Dim Zip As New CDynaZip
Dim XIBRead As New viVDFReader.VDFXib
Save = FAIL
MoveFirst
'
' Edit to remove temp file directory structure
'
Do While Not EOF
EditItem Line, Offset
MoveNext
Loop
'
' save XML file to temp directory
'
m_XML_DOM.Save m_UserLnkFile
'
' zip file into a file called user.xib
'
If (Zip.AddFile(FullPath, m_UserLnkFile)) Then
'
' save user.xib to the VDF file
'
Save = XIBRead.SaveToZipFile(szVD
End If
End Function
Private Sub ProcessError()
On Error Resume Next
Dim Error As IXMLDOMParseError
Set Error = m_XML_DOM.parseError
m_Error = Error.ErrorCode
m_szError = Error.reason + "Line: " + CStr(Error.Line)
Set Error = Nothing
End Sub
Private Sub Class_Initialize()
m_UserLnkFile = GetTempPath() + UserLNK
End Sub
Private Sub Class_Terminate()
Set m_XML_DOM = Nothing
Set m_ActiveNode = Nothing
End Sub
ASKER
It does't work. The error message I got is
Microsoft VBScript runtime (0x800A01A8)
Object required: 'oXML.documentelement.chil dnodes(... ).attribut es'.
If you want to pass Node object to function what's the syntex. Becase I have function ,I pass Node.xml to function instead of node object, inside the function If I want to output name of node, it always like "#text", I don't know what's wrong.
If you want to test to see whether or not a node has attribute what's the syntax.
Microsoft VBScript runtime (0x800A01A8)
Object required: 'oXML.documentelement.chil
If you want to pass Node object to function what's the syntex. Becase I have function ,I pass Node.xml to function instead of node object, inside the function If I want to output name of node, it always like "#text", I don't know what's wrong.
If you want to test to see whether or not a node has attribute what's the syntax.
ASKER
It does't work. The error message I got is
Microsoft VBScript runtime (0x800A01A8)
Object required: 'oXML.documentelement.chil dnodes(... ).attribut es'.
If you want to pass Node object to function what's the syntex. Becase I have function ,I pass Node.xml to function instead of node object, inside the function If I want to output name of node, it always like "#text", I don't know what's wrong.
If you want to test to see whether or not a node has attribute what's the syntax.
Microsoft VBScript runtime (0x800A01A8)
Object required: 'oXML.documentelement.chil
If you want to pass Node object to function what's the syntex. Becase I have function ,I pass Node.xml to function instead of node object, inside the function If I want to output name of node, it always like "#text", I don't know what's wrong.
If you want to test to see whether or not a node has attribute what's the syntax.
It should be something like
oNode.Attributes.getNamedI tem("Name" ).Text
oNode.Attributes.getNamedI
trying to read the attribute value when there is not one will always generate an error.
you can create a function to check existence like
function AttributeExists(node, strAttribute)
on error resume next
dim strTemp
strTemp = node.attributes.getNameIte m("name"). text
'trap for error
if Err.number <> 0 then
AttributeExists = False
else
AttributeExists = True
end if
end function
ps, I have not tried to run this function, just typed it in.
you can create a function to check existence like
function AttributeExists(node, strAttribute)
on error resume next
dim strTemp
strTemp = node.attributes.getNameIte
'trap for error
if Err.number <> 0 then
AttributeExists = False
else
AttributeExists = True
end if
end function
ps, I have not tried to run this function, just typed it in.
Or maybe better yet, create a function to pull your attribute. Pass a default value to use if attribute is not there
function GetAttributeValue(node, strAttribute, strDefault)
on error resume next
dim strTemp
strTemp = node.attributes.getNameIte m("name"). text
'trap for error
if Err.number <> 0 then
GetAttributeValue = strDefault
else
GetAttributeValue = strTemp
end if
end function
ps, I have not tried to run this function, just typed it in.
function GetAttributeValue(node, strAttribute, strDefault)
on error resume next
dim strTemp
strTemp = node.attributes.getNameIte
'trap for error
if Err.number <> 0 then
GetAttributeValue = strDefault
else
GetAttributeValue = strTemp
end if
end function
ps, I have not tried to run this function, just typed it in.
John,
If you are going to cut and paste my code into your solution, I would appreciate the credit.
Thanks
Dave
If you are going to cut and paste my code into your solution, I would appreciate the credit.
Thanks
Dave
ASKER
It always return the default value, it does't work. Sorry.
ASKER
It always return the default value, it does't work. Sorry.
ASKER
It always return the default value, it does't work. Sorry.
Here is alot of junk, but is shows you haw to use the getattribute:
sub document_onmouseover
set curObj = window.event.srcElement
if left(curObj.id,3) = "cmd" then
if not curObj.disabled then
curObj.classname = "cmdMouseOver"
end if
end if
if not isnull(curObj.getAttribute ("statuste xt")) then
window.status = curObj.getAttribute("statu stext")
end if
end sub
~Turbosig (should be some code inhere you can use.)
sub document_onmouseover
set curObj = window.event.srcElement
if left(curObj.id,3) = "cmd" then
if not curObj.disabled then
curObj.classname = "cmdMouseOver"
end if
end if
if not isnull(curObj.getAttribute
window.status = curObj.getAttribute("statu
end if
end sub
~Turbosig (should be some code inhere you can use.)
Dave, Had I cut a pasted your code, you would get credit from me. I did not cut one line of code from you.
BTW: First of all, a major rule in web development is don't use property set,get and lets. Number 2 huizu01 stated that he already knew how to do this in VB therefore another vb example should not be needed.
John
BTW: First of all, a major rule in web development is don't use property set,get and lets. Number 2 huizu01 stated that he already knew how to do this in VB therefore another vb example should not be needed.
John
John, I'll give you a 100 point question and an "A" if you can provide me with the con's of get/set/let`s for the web.
I have never heard that, and would like to know what is wrong with it.
Thanks
-Dave
I have never heard that, and would like to know what is wrong with it.
Thanks
-Dave
I'm going to post that question on get/set/let... be looking for it!
ASKER
This syntex is right. Because I have recursive function, so last node is text, it does't have collection of attribute, so I need to use Node.childnodes(i).parentn ode.attrib utes.getNa meItem("na me").text.
Try this one in asp....
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<%
dim xmlString, oXML, strOwners
' use some xml
xmlString = "<list><owner status=""1"">Ahmad</owner> <owner status=""2"">Ali</owner><o wner status=""3"">Minah</owner> <owner status=""4"">Ahmad</owner> </list>"
' set up object
set oXML = server.CreateObject("Micro soft.XMLDO M")
oXML.async = false
oXML.loadxml xmlString
%>
<SELECT NAME=Value>
<OPTION VALUE="">Pick one </option>
<%
' get the owners from the xml doc
set selNodes= oXML.selectNodes("//owner" )
' start the string of owners to check against
strOwners = "|"
' loop through the nodes in the list, write them out if not already present
for each item in selNodes
if instr(strOwners, "|" & item.text & "|") = 0 then
strOwners = strOwners & item.text & "|"
response.write "<option value=""" & item.attributes.getNamedIt em("status ").text & "2"">" & item.text & "</option>"
end if
next
%>
</select>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<%
dim xmlString, oXML, strOwners
' use some xml
xmlString = "<list><owner status=""1"">Ahmad</owner>
' set up object
set oXML = server.CreateObject("Micro
oXML.async = false
oXML.loadxml xmlString
%>
<SELECT NAME=Value>
<OPTION VALUE="">Pick one </option>
<%
' get the owners from the xml doc
set selNodes= oXML.selectNodes("//owner"
' start the string of owners to check against
strOwners = "|"
' loop through the nodes in the list, write them out if not already present
for each item in selNodes
if instr(strOwners, "|" & item.text & "|") = 0 then
strOwners = strOwners & item.text & "|"
response.write "<option value=""" & item.attributes.getNamedIt
end if
next
%>
</select>
</BODY>
</HTML>
Node.childnodes.Item(i).at
I don't remember if it works both ways or not.
John