Deserialize an XML file and insert into a MySQL database

0

A save to the galera here, How to read XML files so data can be inserted into a database . The problem is to read the XML and deserialize, since the return is blank because the insert in the database is quiet. I'm using as vb.net , The file structure is as follows authors can have several, like 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 at 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
    
asked by anonymous 11.05.2018 / 04:12

0 answers