Document Class as XML?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lars Netzel

    #1

    Document Class as XML?

    Hello!

    I have written a few Classes and inheriting Classes in VB and I would like
    to export these as XML...

    Is there any programs or maybe even features in Visual Studio to produce
    this?

    The reason is that the classes are to be populated thru XML files (that I
    recieve from another company) in runtime and I need to create the XML schema
    and give to the the company so they know how to send the information to
    me...

    best regards
    /Lars


  • marcmc

    #2
    RE: Document Class as XML?

    I dunno if i'm on the right track here as I've never used classes to xml.
    However, it's data so like any other form of data so I have always defined
    my schema, loaded it and fed the structure into a datas et through
    ReadXMLSchema & XML Text Reader as follows:

    Dim fs As FileStream = New FileStream(file Name, FileMode.Open,
    FileAccess.Read )
    Dim xtr As XmlTextReader = New XmlTextReader(f s)
    dsSettings = New DataSet
    Try
    dsSettings.Read XmlSchema(xtr)
    Catch ex As XmlException
    MessageBox.Show (ex.ToString)
    End Try

    xtr.Close()

    Then... loaded the XML file with data(in your case your class has the data)
    with...

    If File.Exists(Set tingsFileName) Then
    Dim fsXML As FileStream = New FileStream(Sett ingsFileName,
    FileMode.Open, FileAccess.Read Write)
    Dim xtrXML As XmlTextReader = New XmlTextReader(f sXML)
    dsSettings.Read Xml(xtrXML)
    xtrXML.Close()
    Else
    Return -1
    End If

    And used a getData function like:

    Private Function GetSettings()

    Dim tbl As DataTable = dsSettings.Tabl es("Settings")
    If tbl.Rows.Count > 0 Then
    Dim row As DataRow = tbl.Rows(0)
    XMLData1 = row("data1")
    XMLData2 = row("data2")... .etc
    Else
    Return -1
    End If

    End Function

    hope this helps

    Comment

    Working...