AJUDA PARA LER UM XML

KERPLUNK 12/02/2014 16:29:16
#434661
Veja um exemplo simples do uso do xsd clicando aqui
KERPLUNK 13/02/2014 10:26:52
#434710
E então, conseguiu desenrolar aí?
ANGELOATA 13/02/2014 12:32:21
#434721
nada ainda, surgiu alguns entraves aqui no trabalho e to tendo que resolver, acho q ate amanha consigo mexer de novo
ANGELOATA 13/02/2014 13:50:27
#434726
Certo fiz a serialização, coloquei o codigo na aplicação so que estou com mais uma duvida

no trecho

Dim ser As New XmlSerializer(GetType(Report))
Dim resultadoFinal As Report
Dim path As String = [Ô]C:\program files\microsoft visual studio 10.0\vc\arq.xml[Ô]
Using reader As XmlReader = XmlReader.Create(path)
resultadoFinal = DirectCast(ser.Deserialize(reader), Report)
End Using

Vc faz pegando o arquivo externo e no meu caso estou pegando o conteudo direto de um webservice, ou seja o xml esta com o conteudo numa variavel do tipo string.

Como faço para deserealizar a partir de uma variavel?
KERPLUNK 13/02/2014 15:50:05
#434738
Praticamente a mesma coisa. Só que ao invés de um xmlReader, você vai usar um StringReader:

Using reader As New StringReader(conteudo)
resultadoFinal = DirectCast(ser.Deserialize(reader), Report)
End Using
ANGELOATA 14/02/2014 11:24:58
#434772
Cara fiz a conversao do xml coloquei no projeto e ao executar da o seguinte erro:

Dim ser As New XmlSerializer(GetType(Report))

Não é possível gerar uma classe temporária (result=1).
error CS0030: Não é possível converter o tipo [ô]fast.ReportRecordField[][ô] em [ô]fast.ReportRecordField[ô]
error CS0029: Não é possível converter implicitamente o tipo [ô]fast.ReportRecordField[ô] em [ô]fast.ReportRecordField[][ô]

O que pode ser?
ANGELOATA 14/02/2014 11:29:55
#434773
Segue a classe gerada pelo xsd

[ô]------------------------------------------------------------------------------
[ô] <auto-generated>
[ô] This code was generated by a tool.
[ô] Runtime Version:4.0.30319.586
[ô]
[ô] Changes to this file may cause incorrect behavior and will be lost if
[ô] the code is regenerated.
[ô] </auto-generated>
[ô]------------------------------------------------------------------------------

Option Strict Off
Option Explicit On

Imports System.Xml.Serialization

[ô]
[ô]This source code was auto-generated by xsd, Version=4.0.30319.1.
[ô]

[ô][ô][ô]<remarks/>
<System.CodeDom.Compiler.GeneratedCodeAttribute([Ô]xsd[Ô], [Ô]4.0.30319.1[Ô]), _
System.SerializableAttribute(), _
System.Diagnostics.DebuggerStepThroughAttribute(), _
System.ComponentModel.DesignerCategoryAttribute([Ô]code[Ô]), _
System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=true), _
System.Xml.Serialization.XmlRootAttribute([Namespace]:=[Ô][Ô], IsNullable:=false)> _
Partial Public Class Report

Private recordField()() As ReportRecordField

Private objectNameField As String

Private storeNameField As String

Private execDateField As String

Private fromRecordField As String

Private toRecordField As String

Private parName1Field As String

Private parValue1Field As String

Private parName2Field As String

Private parValue2Field As String

Private parName3Field As String

Private parValue3Field As String

Private parName4Field As String

Private parValue4Field As String

Private parName5Field As String

Private parValue5Field As String

Private parName6Field As String

Private parValue6Field As String

Private parName7Field As String

Private parValue7Field As String

Private parName8Field As String

Private parValue8Field As String

Private recordsField As String

Private readRecordsField As String

[ô][ô][ô]<remarks/>
<System.Xml.Serialization.XmlArrayAttribute(Form:=System.Xml.Schema.XmlSchemaForm.Unqualified), _
System.Xml.Serialization.XmlArrayItemAttribute([Ô]Field[Ô], GetType(ReportRecordField), Form:=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable:=false)> _
Public Property Record() As ReportRecordField()()
Get
Return Me.recordField
End Get
Set
Me.recordField = value
End Set
End Property

[ô][ô][ô]<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute()> _
Public Property ObjectName() As String
Get
Return Me.objectNameField
End Get
Set
Me.objectNameField = value
End Set
End Property

[ô][ô][ô]<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute()> _
Public Property StoreName() As String
Get
Return Me.storeNameField
End Get
Set
Me.storeNameField = value
End Set
End Property

[ô][ô][ô]<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute()> _
Public Property ExecDate() As String
Get
Return Me.execDateField
End Get
Set
Me.execDateField = value
End Set
End Property

[ô][ô][ô]<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute()> _
Public Property FromRecord() As String
Get
Return Me.fromRecordField
End Get
Set
Me.fromRecordField = value
End Set
End Property

[ô][ô][ô]<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute()> _
Public Property ToRecord() As String
Get
Return Me.toRecordField
End Get
Set
Me.toRecordField = value
End Set
End Property

[ô][ô][ô]<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute()> _
Public Property ParName1() As String
Get
Return Me.parName1Field
End Get
Set
Me.parName1Field = value
End Set
End Property

[ô][ô][ô]<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute()> _
Public Property ParValue1() As String
Get
Return Me.parValue1Field
End Get
Set
Me.parValue1Field = value
End Set
End Property

[ô][ô][ô]<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute()> _
Public Property ParName2() As String
Get
Return Me.parName2Field
End Get
Set
Me.parName2Field = value
End Set
End Property

[ô][ô][ô]<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute()> _
Public Property ParValue2() As String
Get
Return Me.parValue2Field
End Get
Set
Me.parValue2Field = value
End Set
End Property

[ô][ô][ô]<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute()> _
Public Property ParName3() As String
Get
Return Me.parName3Field
End Get
Set
Me.parName3Field = value
End Set
End Property

[ô][ô][ô]<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute()> _
Public Property ParValue3() As String
Get
Return Me.parValue3Field
End Get
Set
Me.parValue3Field = value
End Set
End Property

[ô][ô][ô]<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute()> _
Public Property ParName4() As String
Get
Return Me.parName4Field
End Get
Set
Me.parName4Field = value
End Set
End Property

[ô][ô][ô]<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute()> _
Public Property ParValue4() As String
Get
Return Me.parValue4Field
End Get
Set
Me.parValue4Field = value
End Set
End Property

[ô][ô][ô]<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute()> _
Public Property ParName5() As String
Get
Return Me.parName5Field
End Get
Set
Me.parName5Field = value
End Set
End Property

[ô][ô][ô]<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute()> _
Public Property ParValue5() As String
Get
Return Me.parValue5Field
End Get
Set
Me.parValue5Field = value
End Set
End Property

[ô][ô][ô]<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute()> _
Public Property ParName6() As String
Get
Return Me.parName6Field
End Get
Set
Me.parName6Field = value
End Set
End Property

[ô][ô][ô]<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute()> _
Public Property ParValue6() As String
Get
Return Me.parValue6Field
End Get
Set
Me.parValue6Field = value
End Set
End Property

[ô][ô][ô]<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute()> _
Public Property ParName7() As String
Get
Return Me.parName7Field
End Get
Set
Me.parName7Field = value
End Set
End Property

[ô][ô][ô]<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute()> _
Public Property ParValue7() As String
Get
Return Me.parValue7Field
End Get
Set
Me.parValue7Field = value
End Set
End Property

[ô][ô][ô]<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute()> _
Public Property ParName8() As String
Get
Return Me.parName8Field
End Get
Set
Me.parName8Field = value
End Set
End Property

[ô][ô][ô]<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute()> _
Public Property ParValue8() As String
Get
Return Me.parValue8Field
End Get
Set
Me.parValue8Field = value
End Set
End Property

[ô][ô][ô]<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute()> _
Public Property Records() As String
Get
Return Me.recordsField
End Get
Set
Me.recordsField = value
End Set
End Property

[ô][ô][ô]<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute()> _
Public Property ReadRecords() As String
Get
Return Me.readRecordsField
End Get
Set
Me.readRecordsField = value
End Set
End Property
End Class

[ô][ô][ô]<remarks/>
<System.CodeDom.Compiler.GeneratedCodeAttribute([Ô]xsd[Ô], [Ô]4.0.30319.1[Ô]), _
System.SerializableAttribute(), _
System.Diagnostics.DebuggerStepThroughAttribute(), _
System.ComponentModel.DesignerCategoryAttribute([Ô]code[Ô]), _
System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=true)> _
Partial Public Class ReportRecordField

Private nameField As String

Private valueField As String

[ô][ô][ô]<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute()> _
Public Property Name() As String
Get
Return Me.nameField
End Get
Set
Me.nameField = value
End Set
End Property

[ô][ô][ô]<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute()> _
Public Property Value() As String
Get
Return Me.valueField
End Get
Set
Me.valueField = value
End Set
End Property
End Class

[ô][ô][ô]<remarks/>
<System.CodeDom.Compiler.GeneratedCodeAttribute([Ô]xsd[Ô], [Ô]4.0.30319.1[Ô]), _
System.SerializableAttribute(), _
System.Diagnostics.DebuggerStepThroughAttribute(), _
System.ComponentModel.DesignerCategoryAttribute([Ô]code[Ô]), _
System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=true), _
System.Xml.Serialization.XmlRootAttribute([Na
KERPLUNK 14/02/2014 11:34:02
#434774
é um erro conhecido do xsd. Ao gerar o arquivo .xsd, você deve incluir um atributo dummy antes de converter para classes:

<xs:sequence maxOccurs=[Ô]unbounded[Ô]>
<xs:element ../>
<xs:sequence>
<xs:attribute name=[Ô]tmp[Ô] type=[Ô]xs:string[Ô] /> <-- adicione isso


No xsd vai ter algo parecido com as 3 primeiras linhas do exemplo, simplesmente adicione uma linha [Ô]tmp[Ô] como mostrado.
ANGELOATA 14/02/2014 11:47:41
#434776
Cara

Adicionei a linha mas ainda nao deu certo. ve se esta correto:

<?xml version=[Ô]1.0[Ô] encoding=[Ô]utf-8[Ô]?>
<xs:schema id=[Ô]NewDataSet[Ô] xmlns=[Ô][Ô] xmlns:xs=[Ô]http://www.w3.org/2001/XMLSchema[Ô] xmlns:msdata=[Ô]urn:schemas-microsoft-com:xml-msdata[Ô]>
<xs:element name=[Ô]Report[Ô]>
<xs:complexType>
<xs:sequence>
<xs:element name=[Ô]Record[Ô] minOccurs=[Ô]0[Ô] maxOccurs=[Ô]unbounded[Ô]>
<xs:complexType>
<xs:sequence>
<xs:element name=[Ô]Field[Ô] minOccurs=[Ô]0[Ô] maxOccurs=[Ô]unbounded[Ô]>
<xs:complexType>
<xs:attribute name=[Ô]Name[Ô] type=[Ô]xs:string[Ô] />
<xs:attribute name=[Ô]Value[Ô] type=[Ô]xs:string[Ô] />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name=[Ô]ObjectName[Ô] type=[Ô]xs:string[Ô] />
<xs:attribute name=[Ô]StoreName[Ô] type=[Ô]xs:string[Ô] />
<xs:attribute name=[Ô]ExecDate[Ô] type=[Ô]xs:string[Ô] />
<xs:attribute name=[Ô]FromRecord[Ô] type=[Ô]xs:string[Ô] />
<xs:attribute name=[Ô]ToRecord[Ô] type=[Ô]xs:string[Ô] />
<xs:attribute name=[Ô]ParName1[Ô] type=[Ô]xs:string[Ô] />
<xs:attribute name=[Ô]ParValue1[Ô] type=[Ô]xs:string[Ô] />
<xs:attribute name=[Ô]ParName2[Ô] type=[Ô]xs:string[Ô] />
<xs:attribute name=[Ô]ParValue2[Ô] type=[Ô]xs:string[Ô] />
<xs:attribute name=[Ô]ParName3[Ô] type=[Ô]xs:string[Ô] />
<xs:attribute name=[Ô]ParValue3[Ô] type=[Ô]xs:string[Ô] />
<xs:attribute name=[Ô]ParName4[Ô] type=[Ô]xs:string[Ô] />
<xs:attribute name=[Ô]ParValue4[Ô] type=[Ô]xs:string[Ô] />
<xs:attribute name=[Ô]ParName5[Ô] type=[Ô]xs:string[Ô] />
<xs:attribute name=[Ô]ParValue5[Ô] type=[Ô]xs:string[Ô] />
<xs:attribute name=[Ô]ParName6[Ô] type=[Ô]xs:string[Ô] />
<xs:attribute name=[Ô]ParValue6[Ô] type=[Ô]xs:string[Ô] />
<xs:attribute name=[Ô]ParName7[Ô] type=[Ô]xs:string[Ô] />
<xs:attribute name=[Ô]ParValue7[Ô] type=[Ô]xs:string[Ô] />
<xs:attribute name=[Ô]ParName8[Ô] type=[Ô]xs:string[Ô] />
<xs:attribute name=[Ô]ParValue8[Ô] type=[Ô]xs:string[Ô] />
<xs:attribute name=[Ô]Records[Ô] type=[Ô]xs:string[Ô] />
<xs:attribute name=[Ô]ReadRecords[Ô] type=[Ô]xs:string[Ô] />
<xs:attribute name=[Ô]tmp[Ô] type=[Ô]xs:string[Ô] />
</xs:complexType>
</xs:element>
<xs:element name=[Ô]NewDataSet[Ô] msdata:IsDataSet=[Ô]true[Ô] msdata:UseCurrentLocale=[Ô]true[Ô]>
<xs:complexType>
<xs:choice minOccurs=[Ô]0[Ô] maxOccurs=[Ô]unbounded[Ô]>
<xs:element ref=[Ô]Report[Ô] />
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
Página 2 de 3 [26 registro(s)]
Tópico encerrado , respostas não são mais permitidas