Ver Mensaje Individual
  #1 (permalink)  
Antiguo 10/08/2009, 14:15
budfox
 
Fecha de Ingreso: agosto-2009
Mensajes: 1
Antigüedad: 14 años, 9 meses
Puntos: 0
Exclamación buscar cadena de texto en archivos xml

Estimados, he llegado a un problema que no puedo resolver. he utilizado diversas funciones que hice para leer variables en archivos de texto automatizando pasos de un configurador. En una, necesito leer el valor de un archivo, el problema es que el nombre del valor se repite y me trae el primero. ej:
tomcat server.xml
<!-- Define a SSL HTTP/1.1 Connector on port 8443 -->
<!--
<Connector port="8443" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" disableUploadTimeout="true"
acceptCount="100" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />
-->

<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009"
enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />
----------------------------------------------
funciones que use:
para un archivo con extensión txt me funionó:
Function workerspropfieds(ByVal SearchWord As String, ByVal FileName As String) As Boolean
Dim IsWordFound As Boolean = False
Dim FileContents As String = String.Empty
Dim FileStreamReader As StreamReader
FileStreamReader = New StreamReader(FileName)

Do While FileContents <> SearchWord 'And FileContents Is Nothing
On Error GoTo statement1
FileContents = FileStreamReader.ReadLine()
MsgBox(FileStreamReader.ReadToEnd())
FileStreamReader.Close()
Loop
statement1:
End Function
-----------------------------------------------------------------------
Para este archivo xml intenté: (ya que el otro no me sirvió)
Function text_search_in_file(ByVal palabra As String, ByVal camino As String)

'Abre el archivo httpd.conf y lo lee hasta el final:
Dim texto, position, variable, final, textostr
Dim myTextFile As New StreamReader(camino)
Dim strText As String = myTextFile.ReadToEnd


texto = strText & vbCrLf
MsgBox(texto)
position = InStr(texto, palabra)
texto = VB.Left(texto, InStr(position, texto, vbCrLf) - 1)
texto = VB.Right(texto, Len(texto) - InStrRev(texto, vbCrLf) - 1)

variable = texto
final = VB.Right(variable, Len(variable) - InStr(variable, palabra) - 19)
textostr = VB.Left(final, InStr(final, " "))
MsgBox(textostr)

myTextFile.Close()
End Function
------------------------------------------------------------
espero consejos. muchas gracias