Dim f As FileStream
f = New FileStream(filePath, FileMode.Open, FileAccess.Read)
Dim streamLength As Integer = Convert.ToInt32(f.Length)
Dim fileData As Byte() = New Byte(streamLength) {}
f.Read(fileData, 0, streamLength)
f.Close()
Return System.Text.Encoding.Default.GetString(fileData)
End Function
Private Function LimpiaLCO(ByVal sPath As String, ByVal sFile As String) As String
Dim RutaLCO As [String] = sPath
Dim xmlLCO As String = RutaLCO & sFile
'Dim objReader As New StreamReader(xmlLCO)
Dim sRes As String = FileToString(xmlLCO) 'objReader.ReadToEnd()
Dim posIni As Integer = sRes.LastIndexOf("<?xml", System.StringComparison.Ordinal)
Dim posFin As Integer = sRes.LastIndexOf("</lco:LCO>", System.StringComparison.Ordinal)
sRes = sRes.Substring(posIni, posFin)
posFin = sRes.LastIndexOf("</lco:LCO>", System.StringComparison.Ordinal)
sRes = sRes.Substring(0, posFin)
Dim SW As StreamWriter
Dim origName = xmlLCO.Remove(xmlLCO.Length - 4)
origName += "Clean.XML"
SW = File.CreateText(sPath)
SW.WriteLine(sRes)
SW.WriteLine("</lco:LCO>")
SW.Close()
Return origName
End Function
Private Shared Sub LoadLco(ByVal sPathFileLCO_Clean As String)
'Dim RutaLCO As [String] = sPath
Dim xmlLCO As String = sPathFileLCO_Clean ' RutaLCO & sfileClean
'Cargamos XML
Dim xdoc As XDocument = XDocument.Load(xmlLCO)
'Query
Dim LCO = From Contribuyente In xdoc.Descendants("Contribuyente") _
Select New With {Key .RFC = Contribuyente.Attribute("RFC").Value, _
Key .Certificados = Contribuyente.Descendants("Certificado")}
'Resultado
For Each Contribuyente As Object In LCO
Console.WriteLine(Contribuyente.RFC)
For Each Certificado As Object In Contribuyente.Certificados
Dim Result = ""
Dim xAttribute = Certificado.Attribute("noCertificado")
If xAttribute IsNot Nothing Then
Result += " " & Convert.ToString(xAttribute.Value)
End If
Dim attribute = Certificado.Attribute("ValidezObligaciones")
If attribute IsNot Nothing Then
Result += " " & Convert.ToString(attribute.Value)
End If
Dim xAttribute1 = Certificado.Attribute("EstatusCertificado")
If xAttribute1 IsNot Nothing Then
Result += " " & Convert.ToString(xAttribute1.Value)
End If
Dim attribute1 = Certificado.Attribute("FechaInicio")
If attribute1 IsNot Nothing Then
Result += " " & Convert.ToString(attribute1.Value)
End If
Dim xAttribute2 = Certificado.Attribute("FechaFinal")
If xAttribute2 IsNot Nothing Then
Result += " " & Convert.ToString(xAttribute2.Value)
End If
MessageBox.Show(Result)
Next
Next
End Sub
No hay comentarios:
Publicar un comentario