Foro de elhacker.net

Programación => .NET (C#, VB.NET, ASP) => Mensaje iniciado por: Zeroql en 9 Julio 2010, 21:27 pm



Título: Problema al leer un archivo XML (Solucionado)
Publicado por: Zeroql en 9 Julio 2010, 21:27 pm
Buenas, buneo antes habia hecho un post de como leer este archivo..
resulta que ya lo se leer.
pero me presenta un problema cuando desea leer los keywords.
dejo el code y el archivo xml como lo tengo

Archivo XML
Código
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <Languaje>
  3. <Scopes>
  4. <Scope start="Namespace" End="End Namespace"/>
  5. <Scope start="#Region" End="#End Region"/>
  6. <Scope start="Class" End="End Class"/>
  7. <Scope start="Module" End="End Module"/>
  8. <Scope start="Interface" End="End Iterface"/>
  9. <Scope start="Sub" End="End Sub"/>
  10. <Scope start="Function" End="End Function"/>
  11. <Scope start="Property" End="End Property"/>
  12. <Scope start="Get" End="End Get"/>
  13. <Scope start="Set" End="End Set"/>
  14. </Scopes>
  15. <Coments>
  16. <Coment start="'" End="\n"/>
  17. </Coments>
  18. <Constants>
  19. <Constant text="VbCr"/>
  20. <Constant text="VbCrLf"/>
  21. <Constant text="VbLf"/>
  22. </Constants>
  23. <Operators>
  24. <Pattern Id="." />
  25. <Pattern Id="!" />
  26. <Pattern Id=":" />
  27. <Pattern Id="^" />
  28. <Pattern Id="*" />
  29. <Pattern Id="/" />
  30. <Pattern Id="+" />
  31. <Pattern Id="-" />
  32. <Pattern Id="=" />
  33. <Pattern Id=";" />
  34. <Pattern Id="|" />
  35. <Pattern Id="\" />
  36. <Pattern Id="&gt;" />
  37. <Pattern Id="&lt;" />
  38. </Operators>
  39. <Keys></Keys>
  40. <Keywords>AddHandler AddressOf Alias And AndAlso Ansi As Assembly Auto Boolean ByRef Byte ByVal Call Case Catch CBool CByte CChar CDate CDec CDbl Char CInt Class CLng CObj Const CShort CSng CStr CType Currency Date Decimal Declare Default Delegate Dim DirectCast Do Double Each Else ElseIf End Enum Erase Error Event Exit Explicit False Finally For Friend Function Get GetType GoTo Global Handles If Imports In Inherits Integer Interface Implements Is Let Lib Like Long Loop Me Mod Module MustInherit MustOverride MyBase MyClass Namespace New Next Not Nothing NotInheritable NotOverridable Object On Option Optional Or OrElse Overloads Overridable Overrides ParamArray Preserve Private Property Protected Public RaiseEvent ReadOnly ReDim RemoveHandler Resume Return Select Set Shadows Shared Short Single Static Step Stop String Structure Sub SyncLock Then Throw To True Try TypeOf Unicode Until Variant When While With WithEvents WriteOnly Xor</Keywords>
  41. </Languaje>
  42.  
  43.  


Codigo que uso para leerlo
Código
  1.        ''' <summary>
  2.        ''' Leer todas palabras claves del lenguaje
  3.        ''' </summary>
  4.        Public Sub LoadSintax(ByVal pathSystem As String, ByVal nomLanguaje As String)
  5.            Dim Xml As XmlDocument
  6.            Dim NodeList As XmlNodeList
  7.            Dim Node As XmlNode
  8.            Try
  9.                Xml = New XmlDocument()
  10.                Xml.Load(pathSystem & "\" & nomLanguaje & ".xml")                   'Cargar el archivo XML con la info del lenguaje
  11.                NodeList = Xml.SelectNodes("/Languaje/Scopes/Scope")                'Cargar los nodos a leer
  12.                For Each Node In NodeList                                           'repetir hasta terminar todos los nodos
  13.                    With Node.Attributes
  14.                        sintax.StartMethod.Add(.GetNamedItem("start").Value)
  15.                        sintax.EndMethod.Add(.GetNamedItem("End").Value)
  16.                    End With
  17.                Next
  18.                NodeList = Xml.SelectNodes("/Languaje/Coments/Coment")                  'Cargar el sistema de comentarios
  19.                For Each Node In NodeList
  20.                    With Node.Attributes
  21.                        sintax.startComent.Add(.GetNamedItem("start").Value)
  22.                        sintax.endComent.Add(.GetNamedItem("End").Value)
  23.                    End With
  24.                Next
  25.                NodeList = Xml.SelectNodes("/Languaje/Constants/Constant")              'Cargar las constantes de la aplicacion
  26.                For Each Node In NodeList
  27.                    With Node.Attributes
  28.                        sintax.Constants.Add(.GetNamedItem("text").Value)
  29.                    End With
  30.                Next
  31.                NodeList = Xml.SelectNodes("/Languaje/Operators/Pattern")               'Cargar los operadores del lenguaje
  32.                For Each Node In NodeList
  33.                    With Node.Attributes
  34.                        sintax.Operators.Add(.GetNamedItem("Id").Value)
  35.                    End With
  36.                Next
  37.                Node = Xml.SelectSingleNode("/Languaje/Keywords")                       'Cargar la sintaxis de lenguaje
  38.                Dim strNode() As String = Split(Node.Value, " ")
  39.                For idx = 0 To strNode.Length - 1
  40.                    sintax.Sintaxis.Add(strNode(idx))
  41.                Next
  42.                Node = Xml.SelectSingleNode("/Languaje/Keys")                           'Cargar las palabras clave del lenguaje
  43.                strNode = Split(Node.Value, " ")
  44.                For idx = 0 To strNode.Length - 1
  45.                    sintax.KeySintax.Add(strNode(idx))
  46.                Next
  47.            Catch ex As Exception
  48.                MsgBox(ex.GetType.ToString & vbNewLine & ex.Message.ToString, vbCritical, "ERROR!")
  49.            End Try
  50.        End Sub
  51.  


que tengo mal o que tengo que cambiar para que me lea los keyword y los keys



Título: Re: Problema al leer un archivo XML (Solucionado)
Publicado por: Zeroql en 11 Julio 2010, 15:50 pm
Buenas.... ya arregle el problema.

Para aquellos que experimentan talves el mismo problema les dejo la solucion

Mi problema era k no podia leer los SinlgeNode.

Cambie el code:

Código
  1. Dim strNode() As String = Split(Node.Value, " ")

POR:
Código
  1. Dim strNode() As String = Split(Node.FirstChild.Value, " ")

Espero que a alguien tambien le sirva esta solucion


Título: Re: Problema al leer un archivo XML (Solucionado)
Publicado por: BlackZeroX en 12 Julio 2010, 07:44 am

Solo un consejo esos For Each se pueden simplificar pasando a una Proceso externo  ( Función ).

Dulces Lunas!ˇ.


Título: Re: Problema al leer un archivo XML (Solucionado)
Publicado por: Zeroql en 12 Julio 2010, 15:31 pm
es Cierto...
Pensaba hacerlos recursivosn inclusive.
pero este no es el unico archivo que se va  a leer y hay otros muchisimos mas grandes, decidi que era mejor usar for each.