Re: There must be a better way!
From: Michael Rys [MSFT] (mrys_at_online.microsoft.com)
Date: 06/18/04
- Next message: Michael Rys [MSFT]: "Re: Error !!! SQL XML Bulkload Please help"
- Previous message: Michael Rys [MSFT]: "Re: Using XP_SendMail to send XML Results file"
- In reply to: David Sterling: "There must be a better way!"
- Next in thread: David Sterling: "Re: There must be a better way!"
- Reply: David Sterling: "Re: There must be a better way!"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 17 Jun 2004 23:37:11 -0700
I am sure, we are really all interested in helping, but instead of posting
code, could you please post what you want to do instead?
Thanks
Michael
"David Sterling" <david_sterling@sterling-consulting.com> wrote in message
news:1cefb01c4532e$9c2ccfc0$a501280a@phx.gbl...
> After much futzing about with the XML/XSD for the
> Search.Response, I had to resort to this...
>
> PLEASE Tell me there is a better way!
>
>
> private void ExecuteAQuery(string
> strLookingForWhat)
> {
> // create the area service object
> SearchWebService.QueryService
> queryService = CreateSearchService();
> const string keywordQueryTemplate
> = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><QueryPacket
> xmlns=\"urn:Microsoft.Search.Query\" Revision=\"1000
> \"><Query
> domain=\"QDomain\"><SupportedFormats><Format>urn:Microsoft.
> Search.Response.Document.Document</Format></SupportedFormat
> s><Context><QueryText language=\"en-US\"
> type=\"STRING\">query_text_placeholder</QueryText></Context
>></Query></QueryPacket>";
> const string SQLQueryTemplate
> = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><QueryPacket
> xmlns=\"urn:Microsoft.Search.Query\" Revision=\"1000
> \"><Query domain=\"s2003e:81
> \"><SupportedFormats><Format>urn:Microsoft.Search.Response.
> Document.Document</Format></SupportedFormats><Context><Quer
> yText language=\"en-US\"
> type=\"MSSQLFT\">query_text_placeholder</QueryText></Contex
> t><Range><StartAt>1</StartAt><Count>5</Count></Range></Quer
> y></QueryPacket>";
> string queryString =
> keywordQueryTemplate.Replace("query_text_placeholder",
> strLookingForWhat);
> // DOES NOT WORK (Internal System
> Error Returned):
> string queryString2 =
> SQLQueryTemplate.Replace("query_text_placeholder",
> strLookingForWhat);
> // Init results:
> string queryResults = null;
> try
> {
> queryResults =
> queryService.Query(queryString);
> }
> catch (Exception ExSheesh)
> {
> throw (ExSheesh);
> }
> //
> // Load the returned XML into a
> Document - first create a New XML Document,
> // apply the Response.XSD schema,
> then load the XML from the text received:
> //
> XmlDataDocument NewXmlDoc = new
> XmlDataDocument();
> // Causes error:
> //NewXmlDoc.DataSet.ReadXmlSchema
> ("e:\\SPSSites\\SPSLive\\Response.xsd");
> //NewXmlDoc.DataSet.ReadXmlSchema
> ("/Response.xsd");
> NewXmlDoc.LoadXml(queryResults);
> string XmlDocTableName =
> NewXmlDoc.NameTable.ToString();
> //
> // Get the status:
> //
> XmlNodeList
> Response_StatusNodeList = NewXmlDoc.GetElementsByTagName
> ("Status");
> string ActualStatus =
> Response_StatusNodeList[0].ChildNodes[0].Value;
>
> XmlElement TheRootElement =
> NewXmlDoc.DocumentElement;
>
> XmlNodeList RangeNodeReference =
> NewXmlDoc.GetElementsByTagName("Range");
> XmlNodeList
> RangeNodeContentsReference = RangeNodeReference
> [0].ChildNodes;
>
> DataSet PsuedoResultsDS = new
> DataSet();
> DataTable PsuedoResultsTable = new
> DataTable("SearchResults");
> //
> // Add the columns:
> //
> DataColumn PRTitle = new DataColumn
> ("Title",System.Type.GetType("System.String"));
> DataColumn PRLinkUrl = new
> DataColumn("LinkUrl",System.Type.GetType("System.String"));
> DataColumn PRFileExt = new
> DataColumn("FileExt",System.Type.GetType("System.String"));
> DataColumn PRDescription = new
> DataColumn("Description",System.Type.GetType
> ("System.String"));
> DataColumn PRFileDate = new
> DataColumn("FileDate",System.Type.GetType
> ("System.DateTime"));
> PsuedoResultsTable.Columns.Add
> (PRTitle);
> PsuedoResultsTable.Columns.Add
> (PRLinkUrl);
> PsuedoResultsTable.Columns.Add
> (PRFileExt);
> PsuedoResultsTable.Columns.Add
> (PRDescription);
> PsuedoResultsTable.Columns.Add
> (PRFileDate);
>
> PsuedoResultsDS.Tables.Add
> (PsuedoResultsTable);
> //
> // Now check the nodes within
> <Range> looking for the result set <Results>:
> //
> string sTotalItemsReturned = "";
> int iTotalItemsReturned = 0;
> //
> foreach(XmlNode ARangeNode in
> RangeNodeContentsReference)
> {
> if(ARangeNode.Name
> == "StartAt")
> {
> }
> if(ARangeNode.Name
> == "Count")
> {
> }
> //
> // When we find the
> <TotalAvailable> node, this tells us how many rows we have
> // to process:
> //
> if(ARangeNode.Name
> == "TotalAvailable")
> {
> //
> // Now get how
> many were returned (in <Range><TotalAvailable>) and
> // convert it to
> use for an index:
> //
> XmlNodeList
> TotalValNode = NewXmlDoc.GetElementsByTagName
> ("TotalAvailable");
>
> sTotalItemsReturned = TotalValNode[0].ChildNodes
> [0].InnerText;
> if
> (sTotalItemsReturned != "")
> {
>
> iTotalItemsReturned = Convert.ToInt32
> (sTotalItemsReturned);
> }
> }
> //
> // When we find the
> <Results> node (should be right after TotalAvailable),
> // our results are in the
> nodes below:
> //
> if(ARangeNode.Name
> == "Results")
> {
> //
> // Get a pointer
> to the Row:
> //
> XmlNodeList
> ResultRowNodes = ARangeNode.ChildNodes;
> XmlElement
> TheActualResultRecord = (XmlElement)ResultRowNodes[0];
> //
> // Make sure we
> got something:
> //
> if
> (iTotalItemsReturned > 0)
> {
> //
> // We did -
> each now represents a Row - pull the data out and put
> // it into
> a new record to save to the dataset:
> //
> for (int
> x=0; x < iTotalItemsReturned; x++)
> {
>
> XmlNodeList ColumnsNodes =
> TheActualResultRecord.ChildNodes;
>
> DataRow NewDataRow = PsuedoResultsDS.Tables
> ["SearchResults"].NewRow();
>
> NewDataRow["Title"] = ColumnsNodes[0].InnerText;
>
> string T0 = ColumnsNodes[0].Name;
>
> string T1 = ColumnsNodes[0].InnerText;
>
> NewDataRow["LinkUrl"] = ColumnsNodes[1].ChildNodes
> [0].InnerText;
>
> string T2 = ColumnsNodes[1].ChildNodes
> [0].InnerText;
>
> NewDataRow["FileExt"] = ColumnsNodes[1].ChildNodes
> [0].Attributes[0].InnerText;
>
> string T3 = ColumnsNodes[1].ChildNodes
> [0].Attributes[0].InnerText;
>
> NewDataRow["Description"] = ColumnsNodes
> [2].InnerText;
>
> string T4 = ColumnsNodes[2].InnerText;
>
> NewDataRow["FileDate"] = Convert.ToDateTime
> (ColumnsNodes[3].InnerText);
> //
> //
> Add the new row:
> //
>
> PsuedoResultsDS.Tables["SearchResults"].Rows.Add
> (NewDataRow);
> }
> }
>
> }
>
> }
> dataGrid1.DataSource =
> PsuedoResultsDS;
> dataGrid1.SetDataBinding
> (PsuedoResultsDS,"SearchResults");
>
>
> }
>
>
- Next message: Michael Rys [MSFT]: "Re: Error !!! SQL XML Bulkload Please help"
- Previous message: Michael Rys [MSFT]: "Re: Using XP_SendMail to send XML Results file"
- In reply to: David Sterling: "There must be a better way!"
- Next in thread: David Sterling: "Re: There must be a better way!"
- Reply: David Sterling: "Re: There must be a better way!"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|