locked
Loading an XML file into a XSD dataset - no rows loaded RRS feed

  • Question

  • I'm creating an Class to handle a file. I need to be able to change this file on highly secured PC so I decided to use an XML file as I can email it to the enduser behind just about any firewall.  The problem I have is that the file reads but does not show any rows.

    Here's what I got for the XML file:

    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <ImExJobs>
      <ImExID>1</ImExID>
      <DisplayOrder>1</DisplayOrder>
      <Name>PSI Test</Name>
      <Descript>Get files from PSITest FTP</Descript>
      <Autorun>1</Autorun>
      <SourceType>Fixed</SourceType>
      <FTPSrvr>www.prioritysystems.com</FTPSrvr>
      <FTPUser>psicust</FTPUser>
      <FTPPass>Clippership</FTPPass>
      <FTPPort>21</FTPPort>
      <SourcePath></SourcePath>
      <SourceFilename>*.CB</SourceFilename>
      <FTPDestPath></FTPDestPath>
      <FTPDestFilename>BCHCLPIF</FTPDestFilename>
      <FTPDeleteFilename>*</FTPDeleteFilename>
      <LocalDestPath>C:\KEWILL</LocalDestPath>
      <DeleteSourceFile>No</DeleteSourceFile>
      <SourceArchivePath>C:\Kewill</SourceArchivePath>
      <SourceID>VCA</SourceID>
    </ImExJobs>
    

    THis is the Class code:

    Imports System.IO
    
    Public Class clsImEx
    
      Private sCommonFilesPath As String = System.Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) & "\" & Windows.Forms.Application.CompanyName & "\"
      Private sAppPath As String = (Windows.Forms.Application.StartupPath & "\")
      Private mdsIMEX As New ImExJobConfig
    
      Private sImExJobFilename As String = "ImExConfig.xml"
      Private sImExJobsFileAndPath As String = (sCommonFilesPath & sImExJobFilename)
    
    #Region "Contructors"
    
      Public Sub New()
    
        MyBase.new()
        If Not System.IO.Directory.Exists(sCommonFilesPath) Then
          System.IO.Directory.CreateDirectory(sCommonFilesPath)
        End If
    
        If Not System.IO.File.Exists((sImExJobsFileAndPath)) Then
          System.IO.File.Copy(sAppPath & sImExJobFilename, sImExJobsFileAndPath)
        End If
    
        Try
          CheckImExFile()
        Catch ex As Exception
          Throw New ImExException("New()", ex.Message)
        End Try
    
      End Sub
    
    #End Region
    
    #Region "Public Methods"
    
      Public Sub CheckImExFile4Updates()
    
        Try
          CheckImExFile()
        Catch ex As Exception
          Throw New ImExException("CheckImExFile4Updates", ex.Message)
        End Try
    
      End Sub
    
      Public Sub OpenImExConfig()
    
        Try 'load of Config file
          OpenImExFile()
        Catch ex As Exception
          Throw New ImExException("OpenImExConfig." & ex.Source, "ImEx configuration file not loaded. " & ex.Message)
        End Try
    
      End Sub
    
    #End Region
    
    #Region "Internal Functions"
    
      Private Sub CheckImExFile()
    
        Try
          Dim fiSrc As New FileInfo(sImExJobsFileAndPath)
          Dim fiDest As New FileInfo((sAppPath & sImExJobFilename))
    
          If fiDest.LastWriteTime > fiSrc.LastWriteTime Then
            System.IO.File.Copy(sAppPath & sImExJobFilename, sImExJobsFileAndPath, True)
          End If
        Catch ex As Exception
          Throw New ImExException("CheckImExFile", "ImEx config file update (src=" & (sAppPath & sImExJobFilename) & ") vs. (" & sImExJobsFileAndPath & "): " & ex.Message)
        End Try
    
      End Sub
    
      Private Sub OpenImExFile()
    
        Try 'load of Config file
    
          mdsIMEX.Clear()
          mdsIMEX.ReadXml(sImExJobsFileAndPath, XmlReadMode.Auto)
          Debug.Print(mdsIMEX.ImExJobs.Count)
    
        Catch ex As Exception
          Dim sMsg As String = ex.Message
          If Not ex.InnerException.Message Then
            sMsg += ex.InnerException.Message
          End If
          Throw New ImExException("OpenImExFile." & ex.Source, "ImEx configuration file not loaded. " & ex.Message)
        End Try
    
      End Sub
    
    #End Region
    
    End Class
    
    #Region "Exception Class ImExException"
    
    ''' <summary>
    ''' ImEx custom Exception
    ''' </summary>
    ''' <remarks>allows for catching of our errors</remarks>
    
    Public Class ImExException
      Inherits System.ApplicationException
    
      Private appSourceValue As String
    
      Public Sub New(ByVal LocationId As String, ByVal Message As String)
    
        MyBase.New(Message)
        Me.appSourceValue = "clsImEx." & LocationId
    
      End Sub
    
      Friend Sub LogError()
        My.Application.Log.WriteEntry(Me.Message)
      End Sub
    
      Public Overridable ReadOnly Property AppSource() As String
        Get
          Return appSourceValue
        End Get
      End Property
    
    End Class
    #End Region
    
    

    now the problem is when I to the debug.print in OpenImEx routine. Line reads:

    Debug.Print(mdsIMEX.ImExJobs.Count)
    

    I always get a result of zero.  There is one row in the file.

    Here is the XSD screen shot:

    ANy idea what I missed?

    Thursday, January 12, 2012 10:00 PM

Answers

  • Hi Mudoch2505,

    It code in the link works for Vs2010, you should add existing item into your project.

    I think your problem may relates to "elementForm", here are some steps:

    1. Right Click the xsd file and open with xml editor.

    2. Ctrl+F --->find "elementFormDefault="qualified""

    3. Remove elementFormDefault="qualified"

    4. rerun your code.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Mudoch2505 Monday, January 16, 2012 6:17 PM
    Monday, January 16, 2012 1:45 AM

All replies

  • Hi Mudoch,

    Welcome!

    I think you can try this sample here: http://www.codeproject.com/KB/database/XmlToTypedDataSet.aspx

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, January 13, 2012 9:19 AM
  • Thanks for the assist Alan, I'm looking at it and the article is for VS2003 I believe as the generate from option does not exist in VS2010.

    Anything newer out there and in VB?

    Friday, January 13, 2012 1:50 PM
  • Your problem actually is the because of the format of your XML. You're missing the DataSet name. The XML file should look like this:

    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <ImExJobConfig>
      <ImExJobs>
        <ImExID>1</ImExID>
        <DisplayOrder>1</DisplayOrder>
        <Name>PSI Test</Name>
        <Descript>Get files from PSITest FTP</Descript>
        <Autorun>1</Autorun>
        <SourceType>Fixed</SourceType>
        <FTPSrvr>www.prioritysystems.com</FTPSrvr>
        <FTPUser>psicust</FTPUser>
        <FTPPass>Clippership</FTPPass>
        <FTPPort>21</FTPPort>
        <SourcePath></SourcePath>
        <SourceFilename>*.CB</SourceFilename>
        <FTPDestPath></FTPDestPath>
        <FTPDestFilename>BCHCLPIF</FTPDestFilename>
        <FTPDeleteFilename>*</FTPDeleteFilename>
        <LocalDestPath>C:\KEWILL</LocalDestPath>
        <DeleteSourceFile>No</DeleteSourceFile>
        <SourceArchivePath>C:\Kewill</SourceArchivePath>
        <SourceID>VCA</SourceID>
      </ImExJobs>
    <ImExJobConfig>
    
    

     


    ~~Bonnie Berent [C# MVP]

    geek-goddess-bonnie.blogspot.com
    Sunday, January 15, 2012 5:59 PM
  • Hi Mudoch2505,

    It code in the link works for Vs2010, you should add existing item into your project.

    I think your problem may relates to "elementForm", here are some steps:

    1. Right Click the xsd file and open with xml editor.

    2. Ctrl+F --->find "elementFormDefault="qualified""

    3. Remove elementFormDefault="qualified"

    4. rerun your code.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Mudoch2505 Monday, January 16, 2012 6:17 PM
    Monday, January 16, 2012 1:45 AM
  • Bonnie;

    Thanks, After posting I had gone back over my testing grid and did try this. No change in results, 0 rows loaded.  Thanks for the help.

    Monday, January 16, 2012 6:17 PM
  • Alan; That was the ticket.   But why is this value not openly settable via a property or even really covered in MSDN as to the effect it has?
    Monday, January 16, 2012 6:19 PM