Deserialize an XML file and insert it into a Mysql database

Asked

Viewed 39 times

0

Hail to the crowd here, How to read XML files so that data can be entered into a database . The problem is reading the XML and deserializar, since the retorn is empty, because the insertion in the database is quiet. I am using as , The file structure is as follows, and Authors may have several, as well as Keywords

<records xsi:schemaLocation="http://www.doaj.org/schemas/doajArticles.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <record>
    <language>por</language>
    <publisher></publisher>
    <journalTitle></journalTitle>
    <issn></issn>
    <publicationDate>2013-04-18</publicationDate>
    <volume>6</volume>
    <issue>1</issue>
    <startPage />
    <endPage />
    <doi>00.123456/ebrasilis.v6i1.XXX</doi>
    <publisherRecordId />
    <documentType />
    <title language="por"></title>
    <title language="por" />
    <authors>
      <author>
        <name></name>
        <email />
      </author>
    </authors>
    <abstract language="por" />
    <abstract language="eng" />
    <fullTextUrl format="pdf">http://www.periodico.ebras.bio.br/ojs/index.php/ebras/article/view/ebrasilis.v6i1.XXX</fullTextUrl>
    <keywords language="por"></keywords>
    <keywords language="eng" />
  </record>
</records>

The code in is:

Imports System.Xml.Serialization

<Serializable()>
<XmlRootAttribute("records")>
Public Class Registros
    <XmlArrayItem("author")>
    Public Property authors As List(Of author)
    Public Property language As String
    Public Property publisher As String
    <XmlElementAttribute("journalTitle")> 
    Public journalTitle As String
    Public Property issn As String
    Public Property publicationDate As String
    Public Property volume As String
    Public Property issue As String
    Public Property startPage As String
    Public Property endPage As String
    Public Property publisherRecordId As String
    Public Property documentType As String
    Public Property title As String
    Public Property abstract As String
    Public Property fullTextUrl As String
    Public Property doi As String
    Public Property keyword As keywords

    Public Sub New()
        authors = New List(Of author)()
    End Sub

    Public Class author
        Public Property name As String
        Public Property email As String
    End Class
    Public Class keywords
        <XmlArray("keywords")>
        <XmlArrayItem("keyword")>
        Public keyword As New List(Of String)
    End Class
End Class

Script:

Dim serializer As XmlSerializer = New XmlSerializer(GetType(Registros))
Dim deserialized As Registros

Using reader As New StreamReader(sFileXML)

    deserialized = serializer.Deserialize(reader)

    If deserialized Is Nothing Then
        DivMsg.InnerHtml = "&lt;div class='alert alert-warning'&gt;Objeto está Vazio&lt;/div&gt;"
        Exit Sub
    End If

    MsgBox(deserialized.journalTitle) 
    'usado apenas para testar e retorna em branco assim como todas as variáveis 
End Using
  • what exactly is your doubt?

  • @Leandroangelo the doubt is how to deserialize the data, because with the codes above, I get the blank Msgbox, IE, there is no return.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.