sanjshah12
asked on
Display values from a parsed XML file in console log
Hi,
I am parsing an XML file but as this breaks there is no clear way to see at which record this fails, hence I have added a console log each value such as:
However, I run into a problem when using the console log to output 'Page.Response.Write("<scr ipt>consol e.log('" + dr("duration") + "');</script>")'
as the value duration is a type double when I use console log '"<script>console.log('" to type 'Double' is not valid.'
How am I able to display the value correctly or is there a 'better' method I can use to ascertain when a particular record fails?
Many thanks
I am parsing an XML file but as this breaks there is no clear way to see at which record this fails, hence I have added a console log each value such as:
Dim sqlConn = New SqlConnection(ConfigurationManager.ConnectionStrings("ProjectConnectionString").ToString)
Try
Dim ds As DataSet = New DataSet()
ds.ReadXml(Server.MapPath("~/SampleData.xml"))
Dim dt As DataTable = New DataTable
'dt.Columns.Add("IDNumber", GetType(Integer))
dt.Columns.Add("code", GetType(Integer))
dt.Columns.Add("stage", GetType(String))
dt.Columns.Add("systemplantreference", GetType(String))
dt.Columns.Add("equipmentdescription", GetType(String))
dt.Columns.Add("[level]", GetType(String))
dt.Columns.Add("location", GetType(String))
dt.Columns.Add("detailsnotes", GetType(String))
dt.Columns.Add("duration", GetType(Integer))
dt.Columns.Add("targetreportdate", GetType(Integer))
dt.Columns.Add("progress", GetType(Integer))
dt.Columns.Add("reporteddate", GetType(DateTime))
dt.Columns.Add("start", GetType(DateTime))
dt.Columns.Add("[end]", GetType(DateTime))
Dim dr As DataRow
For Each _dr As DataRow In ds.Tables(0).Rows
dr = dt.NewRow
'dr("IDNumber") = _dr(0)
'Page.Response.Write("<script>console.log('IDNUMBER: " + _dr(0) + "');</script>")
dr("code") = If(Not String.IsNullOrEmpty(_dr(1)), Convert.ToInt16(_dr(1)), DBNull.Value)
Page.Response.Write("<script>console.log('" + dr("code") + "');</script>")
dr("stage") = _dr(2)
Page.Response.Write("<script>console.log('" + dr("stage") + "');</script>")
dr("systemplantreference") = _dr(3)
Page.Response.Write("<script>console.log('" + dr("systemplantreference") + "');</script>")
dr("equipmentdescription") = _dr(4)
Page.Response.Write("<script>console.log('" + dr("equipmentdescription") + "');</script>")
dr("[level]") = _dr(5)
Page.Response.Write("<script>console.log('" + dr("[level]") + "');</script>")
dr("location") = _dr(6)
Page.Response.Write("<script>console.log('" + dr("location") + "');</script>")
dr("detailsnotes") = _dr(7)
Page.Response.Write("<script>console.log('" + dr("detailsnotes") + "');</script>")
dr("duration") = If(Not String.IsNullOrEmpty(_dr(8)), Convert.ToInt16(_dr(8)), DBNull.Value)
Page.Response.Write("<script>console.log('" + dr("duration") + "');</script>")
dr("targetreportdate") = If(Not String.IsNullOrEmpty(_dr(9)), Convert.ToInt16(_dr(9)), DBNull.Value)
Page.Response.Write("<script>console.log('" + dr("targetreportdate") + "');</script>")
dr("progress") = If(Not String.IsNullOrEmpty(_dr(10)), Convert.ToInt16(_dr(10)), DBNull.Value)
Page.Response.Write("<script>console.log('" + dr("progress") + "');</script>")
dr("reporteddate") = If(Not String.IsNullOrEmpty(_dr(11)), Convert.ToDateTime(_dr(11)), DBNull.Value)
Page.Response.Write("<script>console.log('" + dr("reporteddate") + "');</script>")
dr("start") = If(Not String.IsNullOrEmpty(_dr(12)), Convert.ToDateTime(_dr(12)), DBNull.Value)
Page.Response.Write("<script>console.log('" + dr("start") + "');</script>")
dr("[end]") = If(Not String.IsNullOrEmpty(_dr(13)), Convert.ToDateTime(_dr(13)), DBNull.Value)
Page.Response.Write("<script>console.log('" + dr("[end]") + "');</script>")
dt.Rows.Add(dr)
Next
Dim sqlCommand = New SqlCommand("spInsertRecordsDataTable", sqlConn)
sqlCommand.CommandType = CommandType.StoredProcedure
sqlCommand.Parameters.AddWithValue("@tblRecords", dt)
sqlConn.Open()
sqlCommand.CommandTimeout = 950
sqlCommand.ExecuteNonQuery()
sqlConn.Close()
Catch ex As Exception
Dim i As Integer = 10
End Try
However, I run into a problem when using the console log to output 'Page.Response.Write("<scr
as the value duration is a type double when I use console log '"<script>console.log('" to type 'Double' is not valid.'
How am I able to display the value correctly or is there a 'better' method I can use to ascertain when a particular record fails?
Many thanks
have you tried to use Convert.ToString or dr[something].ToString() method?
Also I suggest you push the messages to an array and console.log at the end in one script tag
ASKER
Micheal, could you please provide an example.
I do not use VB, but after a quick google I assume something like
Dim logLines As New ArrayList()
logLines.Add("IDNUMBER: " + _dr(0))
...
logLines.Add("\ncode: "+dr("code"))
...
Page.Response.Write("<script>console.log(")
Page.Response.Write(logLines.Join(logLines.ToArray, ","))
Page.Response.Write(")</script>")
I assume you're using SQL Server as backend?
Did you consider using SQL Server to create the XML by using the FOR XML clause?
Did you consider using SQL Server to create the XML by using the FOR XML clause?
ASKER
Yes, I am importing into MSSQL DB
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Are you serious about this?
Page.Response.Write("<script>console.log('" + row("code") + "');</script>")
Page.Response.Write("<script>console.log('" + row("stage") + "');</script>")
Page.Response.Write("<script>console.log('" + row("systemplantreference") + "');</script>")
Page.Response.Write("<script>console.log('" + row("equipmentdescription") + "');</script>")
Page.Response.Write("<script>console.log('" + row("[level]") + "');</script>")
Page.Response.Write("<script>console.log('" + row("location") + "');</script>")
Page.Response.Write("<script>console.log('" + row("detailsnotes") + "');</script>")
Page.Response.Write("<script>console.log('" + row("duration") + "');</script>")
Page.Response.Write("<script>console.log('" + row("targetreportdate") + "');</script>")
Page.Response.Write("<script>console.log('" + row("progress") + "');</script>")
Page.Response.Write("<script>console.log('" + row("reporteddate") + "');</script>")
Page.Response.Write("<script>console.log('" + row("start") + "');</script>")
Page.Response.Write("<script>console.log('" + row("[end]") + "');</script>")
Why a script tag for each console.log???