Jump to content

Recommended Posts

Posted

Hi All,

I have a large xml file that I am trying to read and get any text in between the "<name></name>" brackets then write that text to a log file.

Exp xml:

<name>SOME TEXT</name>

<name>SOME more TEXT</name>

<name>hello world</name>


Output of text file:

SOME TEXT

SOME more TEXT

hello world

 

Ill post what I have of my code shortly.  Thanks

Posted

Did you try anything so far ? Show your code snippet.


Maybe you should also try to start here:

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

close...

_FileCreate("DataClasses.xml")
FileWrite("DataClasses.xml","<root><name>SOME TEXT</name><name>SOME more TEXT</name><name>hello world</name></root>" )

$File = "DataClasses.xml"
$oXML = ObjCreate("Microsoft.XMLDOM")
$oXML.Load($File)
$oNodes = $oXML.selectNodes('//name')
For $oNode In $oNodes
    ConsoleWrite($oNode.text & @CRLF)
Next

 

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Posted

Not sure why you need an object to read a plain text file (even if the extension is .xml)

#include <String.au3>
#include <Array.au3>

Global $sXml = @TAB & "<name>SOME TEXT</name>" & @CRLF & @CRLF & @TAB & "<name>SOME more TEXT</name>" & @CRLF & @CRLF & @TAB & "<name>hello world</name>"
Global $sLog = ""

; Option 1
Global $aStringBetween = _StringBetween($sXml, "<name>", "</name>")
_ArrayDisplay($aStringBetween, "_StringBetween")

; Option 2, bypassing _StringBetween (which just uses StringRegExp anyway)
Global $aRegExp = StringRegExp($sXml, "<name>(.*)</name>", 3)
_ArrayDisplay($aRegExp, "StringRegExp")

For $iName = 0 To UBound($aRegExp) - 1
    $sLog &= $aRegExp[$iName] & @CRLF
Next

FileWrite(@ScriptDir & "\Log File.log", StringTrimRight($sLog, 2))

Maybe I'm just weird...

Posted (edited)

It removes all the variability to serialize the contents.  My code will always work...yours will work until an attribute is added.

I do agree that this is a very simple xml as given, but even so, it might have more complexity, and a more specific xpath will grab exactly what you need rather than everything.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...