Pregunta
Soy nuevo en asp y tienen un plazo de entrega en los próximos días.recibo el siguiente xml dentro de un webservice respuesta.
print("<?xml version="1.0" encoding="UTF-8"?>
<user_data>
<execution_status>0</execution_status>
<row_count>1</row_count>
<txn_id>stuetd678</txn_id>
<person_info>
<attribute name="firstname">john</attribute>
<attribute name="lastname">doe</attribute>
<attribute name="emailaddress">john.doe@johnmail.com</attribute>
</person_info>
</user_data>");
¿Cómo puedo analizar esta xml en asp atributos?
Cualquier ayuda es muy apreciada
Gracias Damien
En más análisis, un poco de jabón cosas también se devuelve como el aboce respuesta es de una llamada de servicio web.puedo usar lukes código de abajo?
Solución
Usted necesita leer sobre el analizador de MSXML.Aquí hay un enlace a un buen todo-en-uno ejemplo http://oreilly.com/pub/h/466
Un poco de lectura sobre XPath podra ayudar.Usted puede obtener toda la información que necesita en MSDN.
Robar el código de Lucas excelente respuesta para la agregación de los efectos de:
Dim oXML, oNode, sKey, sValue
Set oXML = Server.CreateObject("MSXML2.DomDocument.6.0") 'creating the parser object
oXML.LoadXML(sXML) 'loading the XML from the string
For Each oNode In oXML.SelectNodes("/user_data/person_info/attribute")
sKey = oNode.GetAttribute("name")
sValue = oNode.Text
Select Case sKey
Case "execution_status"
... 'do something with the tag value
Case else
... 'unknown tag
End Select
Next
Set oXML = Nothing
Otros consejos
Por ASP supongo que te refieres a ASP Clásico?Probar:
Dim oXML, oNode, sKey, sValue
Set oXML = Server.CreateObject("MSXML2.DomDocument.4.0")
oXML.LoadXML(sXML)
For Each oNode In oXML.SelectNodes("/user_data/person_info/attribute")
sKey = oNode.GetAttribute("name")
sValue = oNode.Text
' Do something with these values here
Next
Set oXML = Nothing
El código de arriba se supone que tiene el XML en una variable llamada sXML.Si usted está consumiendo este a través de un ServerXMLHttp solicitud, usted debería ser capaz de utilizar la propiedad ResponseXML de su objeto en lugar de oXML y vaya a la LoadXML paso por completo.
Usted podría tratar de cargar el xml en el objeto xmldocument y, a continuación, analizar el uso de sus métodos.