G
Guest
I'm connecting to an exchange public folder and pulling out contacts via XML.
I can use the .responseText to view the text string. The response from
Exchange in this string is formatted in XML. I'm trying to figure out what I
could use to parse the info out of the response because I need to write the
values to SQL.
Here's the code:
try
{
MSXML2.XMLHTTP40 oXMLHttp = new MSXML2.XMLHTTP40();
//TODO: To list items, uncomment "const bool bListItems = false;"
// const bool bListFolders = true;
const bool bListItems = false;
String sUrl;
//TODO: Replace ExchServer with your Exchange server and UserAlias with
your user alias.
sUrl= "http://cartman/public";
oXMLHttp.open("SEARCH", sUrl, false, "n-sv\\kris", "28273De,");
//TODO: Use this query to list items.
String sQuery;
sQuery = "<?xml version='1.0'?>" +
"<g:searchrequest xmlns:g='DAV:'>" +
"<g:sql>SELECT \"DAV:displayname\", \"DAV:creationdate\",
\"urn:schemas:contacts:telephoneNumber\" " +
"FROM SCOPE('SHALLOW TRAVERSAL OF \"" + sUrl + "\"')" +
" WHERE \"DAV:isfolder\" = " + bListItems.ToString()+
"</g:sql>" +
"</g:searchrequest>";
/*
//TODO: Use this query to list folders.
String sQuery;
sQuery = "<?xml version='1.0'?>" +
"<g:searchrequest xmlns:g='DAV:'>" +
"<g:sql>SELECT \"DAV:displayname\" " +
"FROM SCOPE('SHALLOW TRAVERSAL OF \"" + sUrl + "\"')" +
" WHERE \"DAV:isfolder\" = " + bListFolders.ToString() +
"</g:sql>" +
"</g:searchrequest>";
*/
oXMLHttp.setRequestHeader("Content-Type", "text/xml");
oXMLHttp.setRequestHeader("Translate", "f");
oXMLHttp.setRequestHeader("Content-Length", "" + sQuery.Length);
Console.WriteLine(sQuery);
oXMLHttp.send(sQuery);
// Need to create a stream to pass to the XmlTextReader
// stream = new StringReader(oXMLHttp.responseXML.ToString());
// xtr = new XmlTextReader(stream);
// xtr.WhitespaceHandling = WhitespaceHandling.All;
txtResults.Text = oXMLHttp.responseText;
// if(xtr.Read())
// txtResults.Text = xtr.NodeType.ToString() +
xtr.Name.ToString() + xtr.Value.ToString();
// probably take and return the status number to a literal
// 207 seems to indicate good possibly describe the others
Console.WriteLine(oXMLHttp.status);
Console.WriteLine(oXMLHttp.statusText);
Console.WriteLine(oXMLHttp.responseText);
}
catch (Exception ex)
{
Console.WriteLine("{0} Exception caught.", ex);
}
I can use the .responseText to view the text string. The response from
Exchange in this string is formatted in XML. I'm trying to figure out what I
could use to parse the info out of the response because I need to write the
values to SQL.
Here's the code:
try
{
MSXML2.XMLHTTP40 oXMLHttp = new MSXML2.XMLHTTP40();
//TODO: To list items, uncomment "const bool bListItems = false;"
// const bool bListFolders = true;
const bool bListItems = false;
String sUrl;
//TODO: Replace ExchServer with your Exchange server and UserAlias with
your user alias.
sUrl= "http://cartman/public";
oXMLHttp.open("SEARCH", sUrl, false, "n-sv\\kris", "28273De,");
//TODO: Use this query to list items.
String sQuery;
sQuery = "<?xml version='1.0'?>" +
"<g:searchrequest xmlns:g='DAV:'>" +
"<g:sql>SELECT \"DAV:displayname\", \"DAV:creationdate\",
\"urn:schemas:contacts:telephoneNumber\" " +
"FROM SCOPE('SHALLOW TRAVERSAL OF \"" + sUrl + "\"')" +
" WHERE \"DAV:isfolder\" = " + bListItems.ToString()+
"</g:sql>" +
"</g:searchrequest>";
/*
//TODO: Use this query to list folders.
String sQuery;
sQuery = "<?xml version='1.0'?>" +
"<g:searchrequest xmlns:g='DAV:'>" +
"<g:sql>SELECT \"DAV:displayname\" " +
"FROM SCOPE('SHALLOW TRAVERSAL OF \"" + sUrl + "\"')" +
" WHERE \"DAV:isfolder\" = " + bListFolders.ToString() +
"</g:sql>" +
"</g:searchrequest>";
*/
oXMLHttp.setRequestHeader("Content-Type", "text/xml");
oXMLHttp.setRequestHeader("Translate", "f");
oXMLHttp.setRequestHeader("Content-Length", "" + sQuery.Length);
Console.WriteLine(sQuery);
oXMLHttp.send(sQuery);
// Need to create a stream to pass to the XmlTextReader
// stream = new StringReader(oXMLHttp.responseXML.ToString());
// xtr = new XmlTextReader(stream);
// xtr.WhitespaceHandling = WhitespaceHandling.All;
txtResults.Text = oXMLHttp.responseText;
// if(xtr.Read())
// txtResults.Text = xtr.NodeType.ToString() +
xtr.Name.ToString() + xtr.Value.ToString();
// probably take and return the status number to a literal
// 207 seems to indicate good possibly describe the others
Console.WriteLine(oXMLHttp.status);
Console.WriteLine(oXMLHttp.statusText);
Console.WriteLine(oXMLHttp.responseText);
}
catch (Exception ex)
{
Console.WriteLine("{0} Exception caught.", ex);
}