What No XmlDocument...?
Jun 6, 2007
OK I am working on a SSIS package and am using a script task. I have to get remote xmldocuments from a server. Sounds simple enough. In C# it was easy but for some reason vb.net will not let me do this:
I can do a httpwebrequest and get the xml string into a variable strResponse
But the following will not work. The XmlDocument doesn't exists in the script task the vb code. On a side note I am importing Imports System.Xml in case anyone asks.
Dim doc As New XmlDocument
doc.LoadXml(strResponse)
Could anyone tell me how I would parse the xml elements using a script task?
here is the full code I am working with but all of the xml stuff has that blue squggly line underneathit.
Private Function ParseXmlIntoList(ByVal strResponse As String, ByVal l As List(Of StockInfo)) As List(Of StockInfo)
Dim doc As New XmlDocument
Try
doc.LoadXml(strResponse)
Catch
isError = True
Return l
End Try
Dim root As XmlElement = doc.DocumentElement
Dim list As XmlNodeList = root.SelectNodes("/StockData/Stock")
Dim x As Integer = 0
Dim n As XmlNode
For Each n In list
If l((x + intStartCount)).Symbol = getXMLElement(n, "Symbol") Then
l((x + intStartCount)).Price = Convert.ToDecimal(getXMLElement(n, "Last"))
l((x + intStartCount)).CompanyName = getXMLElement(n, "Name")
x += 1
Else
isError = True
Return l
End If
Next n
intStartCount = intStartCount + 25
Return l
End Function
Any help would be greatly appreciated.
Thanks,
JBelthoff
• Hosts Station is a Professional Asp Hosting Provider
• Position SEO can provide your company with SEO Services at an affordable price
› As far as myself... I do this for fun!
View 1 Replies
May 27, 2006
I would like to return an xmldocument from a 2005 vb clr stored procedure.
This is my definition for the stored procedure. passing in a string, return xmldoc.
Can I not return an xmldoc as output? The solution will build, but not run.
Partial Public Class StoredProcedures
<Microsoft.SqlServer.Server.SqlProcedure()> _
Public Sub SP_Transform(ByVal cc As String, <Out()> ByVal RetValue As XmlDocument)
Error 1 Column, parameter, or variable #2: Cannot find data type XmlDocument. SqlServerProject1
View 1 Replies
View Related
Aug 10, 2007
This is all I have in SSIS Script Task
Imports System.Xml
Public Sub Main()
Dim doc As XmlDocument
doc.Load("C:Data est.xml")
Dts.TaskResult = Dts.Results.Success
End Sub
I get this error
Object reference not set to an instance of an object.
Any idea - Ashok
View 4 Replies
View Related
Oct 23, 2006
Hi, I have xmldocument type that stores xml data. I would like to able to store that data in sql server 2005 as a xml data type. How can I accomplish this using ado sqlcommand? XmlDocument xdoc = new XmlDocument();SqlConnection conn = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["Test"].ConnectionString);conn.Open();SqlCommand cmd = new SqlCommand(); cmd.Connection = conn;cmd.CommandType = CommandType.StoredProcedure;cmd.CommandText = "spStoreApp";cmd.Parameters.AddWithValue("@PersId", "222-22-2222");cmd.Parameters.AddWithValue("@AppData", xdoc);try{cmd.ExecuteNonQuery();Response.Write("Storage of application successful");}catch (SqlException sqlx){Response.Write(sqlx.Message);}conn.Close();thanks in advance.
View 3 Replies
View Related
Feb 22, 2007
Hi there,
How do i load a XML document saved in SQL server as a XML data type into
XmlDocument xdoc = new XmlDocument();xdoc.Load(// INTO HERE );
I can load a xml file saved to disk but haven't figured out how to retrive from a recordset. I have tried the following:
XmlDocument xdoc = new XmlDocument();xdoc.Load(GetXmlFile(pnrID).ToString());
public string GetXmlFile(int pnrID){
SqlConnection cnn = null;SqlCommand cmd = null;
string XML = "";
try {
cnn = new SqlConnection(); cnn.ConnectionString = "Server=;Initial Catalog=;UID=;PWD=;"; cnn.Open();
string selectQry = "SELECT [XML] FROM [TEMP_PNR] WHERE PnrID = @PnrID";
cmd = new SqlCommand(selectQry, cnn);
cmd.Parameters.AddWithValue("@pnrID", pnrID);
SqlDataReader rdr = cmd.ExecuteReader();
if (rdr.Read()) XML = rdr.GetSqlXml(0).ToString();
}
catch (Exception ex) { throw ex; }
finally { cmd.Dispose(); cnn.Close(); }
return XML;
}
But this genereates the following error: Could not find file 'C:Program FilesMicrosoft Visual Studio 8Common7IDESystem.Data.SqlTypes.SqlXml'.
Any idea how i can achive this?
View 5 Replies
View Related
May 25, 2006
The test sub below operates on a SQL Server Table with an xml-type field ("xml"). The purpose of the sub is to learn about storing and retrieving a whole xml document as a single field in a SQL Server table row.When the code saves to the xml field, it somehow automagically strips the xml.document.declaration (<?xml...>). So when it reads the xml field back and tries to create an xmldocument from it, it halts at the xmldocument.load.I order to get the save/retrieve from the xmlfield to work, I add the <?xml declaration to the string when I read it back in from the xml field (this is in the code below).At that point the quickwatch on the string I'm attempting to load into the xmldocument is this:-----------------------------------------------------<?xml version="1.0" encoding="utf-16" ?><Control type="TypeA"><Value1><SubVal1A>Units</SubVal1A><SubVal1Btype="TypeA">Type</SubVal1B></Value1><Value2><SubVal2A>Over</SubVal2A><SubVal2B>Load</SubVal2B></Value2></Control>-----------------------------------------------------The original xml document string is this:-----------------------------------------------------<?xml version="1.0" encoding="utf-16" ?><Control type="TypeA"> <Value1> <SubVal1A>Units</SubVal1A> <SubVal1B type="TypeA">Type</SubVal1B> </Value1> <Value2> <SubVal2A>Over</SubVal2A> <SubVal2B>Load</SubVal2B> </Value2></Control>-----------------------------------------------------which seems to have all the same characters as the quickwatch result above, but clearly is formatted differently because of the indenting.THE FIRST QUESTION: Is there a simpler way to do this whole thing using more appropriate methods that don't require adding the xml.document.declaration back in after reading the .xml field, or don't require using the memorystream to convert the .xml field in order to load it back to the XML document.THE SECOND QUESTION: Why does the original document open in the browser with "utf-16", but when I write the second document back to disk with "utf-16" it won't open...I have to change it to "utf-8" to open the second document in the browser.Here's the test sub'============================================ Public Sub XMLDSTest() '=========================================== Dim ColumnType As String = "XML" '=========================================== '----------Set up dataset, datatable, xmldocument Dim wrkDS As New DSet1() Dim wrkTable As New DSet1.Table1DataTable Dim wrkAdapter As New DSet1TableAdapters.Table1TableAdapter Dim wrkXDoc As New XmlDocument wrkXDoc.Load(SitePath & "App_XML" & "XMLFile.xml") Dim str1 = wrkXDoc.OuterXml Dim wrkRow As DSet1.Table1Row wrkRow = wrkTable.NewRow '=======WRITE to SQL Server============== '------ build new row With wrkRow Dim wrkG As Guid = System.Guid.NewGuid TestKey = wrkG.ToString .RecordKey = TestKey .xml = wrkXDoc.OuterXml '<<< maps to SQL Server xml-type field End With '----- add row to table and update to disk wrkTable.Rows.Add(wrkRow) wrkAdapter.Update(wrkTable) wrkTable.AcceptChanges() '----- clear table wrkTable.Clear() '=======READ From SQL Server ============== '----refill table, read row, wrkAdapter.FillBy(wrkTable, TestKey) Dim wrkRow2 As DSet1.Table1Row = _ wrkTable.Select("RecordKey = '" & TestKey & "'")(0) '===== WRITE TO New .xml FILE =========================== Dim wrkS1 As New StringBuilder Select Case ColumnType Case "XML" '---if xml build xml declaration: '---add this to xml from sql table => <?xml version="1.0" encoding="utf-16" ?> wrkS1.Append("<?xml version=" & Chr(34) & "1.0" & Chr(34)) wrkS1.Append(" encoding=" & Chr(34) & "utf-16" & Chr(34) & " ?>") wrkS1.Append(wrkRow2.xml) End Select Dim wrkBytes As Byte() = (New UnicodeEncoding).GetBytes(wrkS1.ToString) Dim wrkXDoc2 As New XmlDocument Dim wrkStream As New MemoryStream(wrkBytes) wrkXDoc2.Load(wrkStream) '=========================================== '---- this just shows that the file actually was touched Dim wrkN2 As XmlNode = wrkXDoc2.CreateNode(XmlNodeType.Text, "ss", "TestNode2") wrkN2 = wrkXDoc2.SelectSingleNode("//Value1/SubVal1B") wrkN2.Attributes("type").Value = "This was from the xml field" '---------------- '------ update the encoding....otherwise the file won't open in the browser with utf-16 Dim wrkN1 As XmlNode = wrkXDoc2.CreateNode(XmlNodeType.Element, "ss", "TestNode") wrkN1 = wrkXDoc2.FirstChild wrkN1.InnerText = Replace(wrkN1.InnerText, "utf-16", "utf-8") '------------Now write the file back as an .xml file Dim wrkFilePath As String = SitePath & "App_XML" & "XMLFile2.xml" Dim wrkXW As XmlWriter = XmlWriter.Create(wrkFilePath) wrkXDoc2.WriteContentTo(wrkXW) wrkXW.Close() End Sub===============================
View 8 Replies
View Related