Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to convert XML string to XML document in VB

Status
Not open for further replies.

neon2000

Programmer
Nov 10, 2004
10
CA
Does anyone can help me convert following javacript in ASP
into VB in ASP.NET?

function phonePush2(phoneIP, URI1, URI2, userID, password)
{
var authstring = text2base64(userID + ":" + password);

var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

var pushxml = "<CiscoIPPhoneExecute><ExecuteItem Priority=\"0\" URL=\"" + URI1 + "\"/><ExecuteItem Priority=\"0\" URL=\"" + URI2 + "\"/></CiscoIPPhoneExecute>";
pushxml = "XML=" + Server.UrlEncode(pushxml);

xmlhttp.Open("POST", " + phoneIP + "/CGI/Execute", false);
xmlhttp.setRequestHeader("Authorization", "Basic " + authstring);
xmlhttp.setRequestHeader("Connection", "close");
xmlhttp.setRequestHeader("Content-type", "application/x- xmlhttp.Send(pushxml);

return xmlhttp.responseText;
}

Following is the code converted by myself, but I got error
which was read as: "A string literal was expected, but no opening quote character was found".

Function phonePush2(ByVal phoneIP As String, ByVal URI1 As String, ByVal URI2 As String, ByVal userID As String, ByVal password As String)

Dim authstring As String = text2base64(userID + ":" + password)
Dim xmlhttp As New MSXML2.XMLHTTP
Dim xmlDoc As New MSXML2.DOMDocument
Dim pushxml As String = "<CiscoIPPhoneExecute><ExecuteItem Priority=" + Chr(34) + "0" + Chr(34) + " URL=" + URI1 + "/><ExecuteItem Priority=" + Chr(34) + "0" + Chr(34) + " URL=" + URI2 + "/></CiscoIPPhoneExecute>"

pushxml = "<?xml version=" + Chr(34) + "1.0" + Chr(34) + " encoding=" + Chr(34) + "iso-8859-1" + Chr(34) + "?>" + pushxml
If (xmlDoc.loadXML(pushxml)) Then
xmlhttp.open("POST", " + phoneIP + "/CGI/Execute", False)
xmlhttp.setRequestHeader("Authorization", "Basic " + authstring)
xmlhttp.setRequestHeader("Connection", "close")
xmlhttp.setRequestHeader("Content-type", "application/x- xmlhttp.send(xmlDoc.xml)

Else
Response.Write(xmlDoc.parseError.reason)
End If
End Function
 
Doing string concatenation to build your XML is a bad idea -- you get into all sorts of problems with character set encodings (your document is declared as iso-8859-1, but the .net strings you're using are UTF-16).

Try something like this:
Code:
Dim xmlDoc As New XmlDocument
Dim xmlRootElem As XmlElement
Dim xmlElem As XmlElement
Dim xmlAttr As XmlAttribute
Dim xmlDecl As XmlDeclaration

xmlDecl = xmlDoc.CreateXmlDeclaration("1.0", "ISO-8859-1", Nothing)
xmlDoc.AppendChild(xmlDecl)

xmlRootElem = xmlDoc.CreateElement("CiscoIPPhoneExecute")
xmlDoc.AppendChild(xmlRootElem)

xmlElem = xmlDoc.CreateElement("ExecuteItem")
xmlRootElem.AppendChild(xmlElem)

xmlAttr = xmlDoc.CreateAttribute("Priority")
xmlAttr.Value = XmlConvert.ToString(0)
xmlElem.Attributes.Append(xmlAttr)

xmlAttr = xmlDoc.CreateAttribue("URL")
xmlAttr.Value = URI1;
xmlElem.Attributes.Append(xmlAttr)

xmlElem = xmlDoc.CreateElement("ExecuteItem")
xmlRootElem.AppendChild(xmlElem)

xmlAttr = xmlDoc.CreateAttribute("Priority")
xmlAttr.Value = XmlConvert.ToString(0)
xmlElem.Attributes.Append(xmlAttr)

xmlAttr = xmlDoc.CreateAttribue("URL")
xmlAttr.Value = URI2;
xmlElem.Attributes.Append(xmlAttr)
Chip H.


____________________________________________________________________
Click here to learn Ways to help with Tsunami Relief
If you want to get the best response to a question, please read FAQ222-2244 first
 
Chip:
Thank you very much for the response.

I will try to test the solution provided by you.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top