Error with reading XML file from Sharepoint

  • Thread starter Thread starter Coderv9
  • Start date Start date
C

Coderv9

Guest
Hi,

We are trying to read XML file from a sharepoint site. and Code dosent seems to be reading the file at all. It just moves to End Try on this command While xmlfile.Read(). It display the number of nodes in xml but failes to read the contents of XML.

Below is my code:

Private Sub Load3ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles Load3ToolStripMenuItem.Click
Dim sccm_srv_link As String
Dim n = 0
Dim Row1 As DataRow
Try
sccm_srv_link = "https://mysite.com/sites/XXX/_vti_bin/owssvr.dll?Cmd=Display&List={xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxx}&XMLDATA=TRUE&RowLimit=0"
Dim xmlfile As XmlReader
Dim resolver As New XmlUrlResolver
resolver.Credentials = CredentialCache.DefaultCredentials
Dim xmsettings As New XmlReaderSettings
xmsettings.XmlResolver = resolver
xmlfile = XmlReader.Create(sccm_srv_link, xmsettings)
Dim doc As XmlDocument = New XmlDocument()
doc.Load(xmlfile)
Dim root As XmlElement = doc.DocumentElement
Dim elemList As XmlNodeList = root.GetElementsByTagName("z:row")
Dim max As Integer = elemList.Count - 1
While xmlfile.Read()
Select Case xmlfile.NodeType
Case XmlNodeType.Element 'Display beginning of element.
If xmlfile.Name = "z:row" Then
If xmlfile.HasAttributes Then 'If attributes exist
Row1 = table1.NewRow()
While xmlfile.MoveToNextAttribute()

If xmlfile.Name = "ows_LinkTitle" Then
Row1.Item("Host_Name") = xmlfile.Value
End If
If xmlfile.Name = "ows_Service_x0020_TAG" Then
Row1.Item("Service_Tag") = xmlfile.Value
End If
If xmlfile.Name = "ows_Model" Then
Row1.Item("Model") = xmlfile.Value
End If
If xmlfile.Name = "ows_Full_x0020_Name" Then
Row1.Item("Full_Name") = xmlfile.Value
End If
If xmlfile.Name = "ows_LAN_x0020_ID" Then
Row1.Item("User_Name") = xmlfile.Value
End If
If xmlfile.Name = "ows_Location" Then
Row1.Item("Location") = xmlfile.Value
End If
End While
n = n + 1
table1.Rows.Add(Row1)
End If
End If
End Select
DataGridView1.DataSource = table1
DataGridView1.Refresh()
End While
Catch ex As Exception
MsgBox(ex.Message)
Exit Sub
End Try
End Sub


And here is the XML output from the site:

<xml xmlns:s='uuid:XXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
xmlns:dt='uuid:XXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
xmlns:rs='urn:schemas-microsoft-com:rowset'
xmlns:z='#RowsetSchema'>
<s:Schema id='RowsetSchema'>
<s:ElementType name='row' content='eltOnly' rs:CommandTimeout='30'>
<s:AttributeType name='ows_LinkTitle' rs:name='Computer Name' rs:number='1'>
<s:datatype dt:type='string' dt:maxLength='512' />
</s:AttributeType>
<s:AttributeType name='ows_LAN_x0020_ID' rs:name='LAN ID' rs:number='2'>
<s:datatype dt:type='string' dt:maxLength='512' />
</s:AttributeType>
<s:AttributeType name='ows_Full_x0020_Name' rs:name='Full Name' rs:number='3'>
<s:datatype dt:type='string' dt:maxLength='1073741823' />
</s:AttributeType>
<s:AttributeType name='ows_Service_x0020_TAG' rs:name='Service TAG' rs:number='4'>
<s:datatype dt:type='string' dt:maxLength='512' />
</s:AttributeType>
<s:AttributeType name='ows_Model' rs:name='Model' rs:number='5'>
<s:datatype dt:type='string' dt:maxLength='512' />
</s:AttributeType>
<s:AttributeType name='ows_Location' rs:name='Location' rs:number='6'>
<s:datatype dt:type='string' dt:maxLength='512' />
</s:AttributeType>
<s:AttributeType name='ows_Warranty_x0020_Start_x0020_Date' rs:name='Warranty Start Date' rs:number='7'>
<s:datatype dt:type='datetime' dt:maxLength='8' />
</s:AttributeType>
<s:AttributeType name='ows_Warranty_x0020_End_x0020_Date' rs:name='Warranty End Date' rs:number='8'>
<s:datatype dt:type='datetime' dt:maxLength='8' />
</s:AttributeType>
<s:AttributeType name='ows_Status' rs:name='Status' rs:number='9'>
<s:datatype dt:type='string' dt:maxLength='512' />
</s:AttributeType>
<s:AttributeType name='ows_Comments' rs:name='Comments' rs:number='10'>
<s:datatype dt:type='string' dt:maxLength='512' />
</s:AttributeType>
<s:AttributeType name='ows_Editor' rs:name='Modified By' rs:number='11'>
<s:datatype dt:type='string' dt:lookup='true' dt:maxLength='512' />
</s:AttributeType>
<s:AttributeType name='ows_Modified' rs:name='Modified' rs:number='12'>
<s:datatype dt:type='datetime' dt:maxLength='8' />
</s:AttributeType>
</s:ElementType>
</s:Schema>
<rs:data>
<z:row ows_LinkTitle='COMPUTER_NAME' ows_LAN_x0020_ID='User_ID' ows_Full_x0020_Name='User_Name' ows_Service_x0020_TAG='SERVICE_TAG' ows_Model='COMPUTE_MODEL' ows_Location='LOCATION' ows_Warranty_x0020_Start_x0020_Date='2019-12-30 00:00:00' ows_Warranty_x0020_End_x0020_Date='2019-12-30 00:00:00' ows_Status='Status 01' ows_Comments='NO_COMMENTS' ows_Editor='66;#USER_NAME' ows_Modified='2019-12-30 00:00:00' />
<z:row ows_LinkTitle='COMPUTER_NAME' ows_LAN_x0020_ID='User_ID' ows_Full_x0020_Name='User_Name' ows_Service_x0020_TAG='SERVICE_TAG' ows_Model='COMPUTE_MODEL' ows_Location='LOCATION' ows_Warranty_x0020_Start_x0020_Date='2019-12-30 00:00:00' ows_Warranty_x0020_End_x0020_Date='2019-12-30 00:00:00' ows_Status='Status 02' ows_Comments='NO_COMMENTS' ows_Editor='66;#USER_NAME' ows_Modified='2019-12-30 00:00:00' />
<z:row ows_LinkTitle='COMPUTER_NAME' ows_LAN_x0020_ID='User_ID' ows_Full_x0020_Name='User_Name' ows_Service_x0020_TAG='SERVICE_TAG' ows_Model='COMPUTE_MODEL' ows_Location='LOCATION' ows_Warranty_x0020_Start_x0020_Date='2019-12-30 00:00:00' ows_Warranty_x0020_End_x0020_Date='2019-12-30 00:00:00' ows_Status='Status 01' ows_Comments='NO_COMMENTS' ows_Editor='66;#USER_NAME' ows_Modified='2019-12-30 00:00:00' />
<z:row ows_LinkTitle='COMPUTER_NAME' ows_Full_x0020_Name='&lt;div&gt;In Stock&lt;br&gt;&lt;/div&gt;' ows_Service_x0020_TAG='SERVICE_TAG' ows_Model='COMPUTE_MODEL' ows_Location='LOCATION' ows_Warranty_x0020_Start_x0020_Date='2019-12-30 00:00:00' ows_Warranty_x0020_End_x0020_Date='2019-12-30 00:00:00' ows_Status='Status 04' ows_Editor='48;#USER_NAME' ows_Modified='2019-12-30 00:00:00' />
<z:row ows_LinkTitle='COMPUTER_NAME ' ows_LAN_x0020_ID='User_ID' ows_Full_x0020_Name='&lt;div&gt;User_Name&lt;/div&gt;' ows_Service_x0020_TAG='SERVICE_TAG ' ows_Model='COMPUTE_MODEL' ows_Location='LOCATION' ows_Warranty_x0020_Start_x0020_Date='2019-12-30 00:00:00' ows_Warranty_x0020_End_x0020_Date='2019-12-30 00:00:00' ows_Status='Status 03' ows_Editor='67;#USER_NAME' ows_Modified='2019-12-30 00:00:00' />
</rs:data>
</xml>


How ever the above code was able to display output for the below xml file.

<?xml version="1.0" encoding="utf-8"?>
<Report xsi:schemaLocation="Hardware_x0020_Inventory http://mysite.com/Reports?/Reports/...d=Render&amp;rs:Format=XML&amp;rc:Schema=True" Name="Inventory"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="Hardware_x0020_Inventory">
<Tablix1>
<Details_Collection>
<Details Device_Name="Device_name" Model="Device_Model" Serial_Number="Device_Serial" User_Name="User_Name" Full_Name="User_FullName" Location="Location" Last_Used="2019-02-20T00:00:00" />
<Details Device_Name="Device_name" Model="Device_Model" Serial_Number="Device_Serial" User_Name="User_Name" Full_Name="User_FullName" Location="Location" Last_Used="2019-02-20T00:00:00" />
<Details Device_Name="Device_name" Model="Device_Model" Serial_Number="Device_Serial" User_Name="User_Name" Full_Name="User_FullName" Location="Location" Last_Used="2019-02-20T00:00:00" />
<Details Device_Name="Device_name" Model="Device_Model" Serial_Number="Device_Serial" User_Name="User_Name" Full_Name="User_FullName" Location="Location" Last_Used="2019-02-20T00:00:00" />
<Details Device_Name="Device_name" Model="Device_Model" Serial_Number="Device_Serial" User_Name="User_Name" Full_Name="User_FullName" Location="Location" Last_Used="2019-02-20T00:00:00" />
<Details Device_Name="Device_name" Model="Device_Model" Serial_Number="Device_Serial" User_Name="User_Name" Full_Name="User_FullName" Location="Location" Last_Used="2019-02-20T00:00:00" />
</Details_Collection>
</Tablix1>
</Report>

Coderv9

Continue reading...
 
Back
Top