Jump to content

parse xml


Recommended Posts

Not sure how to do this, anyone have any ideas? I have a certain xml file that I import the data to a form, and I want to save that form using the value of a certain tag in the xml file.

TopmostSubform.ActivityTitle.value

Not sure how to word it in Autoit, any suggestions would be helpful. Thanks.

Link to comment
Share on other sites

Not sure how to do this, anyone have any ideas? I have a certain xml file that I import the data to a form, and I want to save that form using the value of a certain tag in the xml file.

TopmostSubform.ActivityTitle.value

Not sure how to word it in Autoit, any suggestions would be helpful. Thanks.

Using COM, you can use Microsoft's XML parser, (someone has started a UDF that aims to get as good as Dales IE.au3) ...

COM too hard?

Don't understand how to use the XML UDFs?

Parse it yourself, it's just text.

Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Link to comment
Share on other sites

Hi,

may show some xml and what you want.

Maybe you can go ahead with _stringBetween

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Using COM, you can use Microsoft's XML parser, (someone has started a UDF that aims to get as good as Dales IE.au3) ...

COM too hard?

Don't understand how to use the XML UDFs?

Parse it yourself, it's just text.

So, in VBS, I'd do it this way:

'----------------------------------------------

' Needs reference to Microsoft XML 2 or better

'----------------------------------------------

Sub doXML()

Dim oShell As Object

Dim sDesktopDir

Set oShell = CreateObject("WScript.Shell")

sDesktopDir = oShell.SpecialFolders("Desktop")

'----------- DO SOME XML STUFF HERE

Dim xml

Set xml = CreateObject("MSXML2.DOMDocument")

xml.async = False

xml.Load (sDesktopDir & "\Request for CME-CPE_data.xml")

Set objNodeList = xml.selectNodes("TopmostSubform/ActivityTitle")

For i = 0 To (objNodeList.Length - 1)

Set objNode = objNodeList.NextNode

MsgBox "I could rename your file to " & objNode.Text

Next

End Sub

__________

Well, at least to grab it, it doesn't copy it to the clipboard there. But, I don't even know how to get this started in Autoit.

Link to comment
Share on other sites

Hi,

may show some xml and what you want.

Maybe you can go ahead with _stringBetween

So long,

Mega

I didn't see _stringBetween in my version, is it only the beta, I didn't try that yet.

The XML looks sorta like this:

<TopmostSubmenu>

<Example1>test</Example1>

<Example2>example</Example2>

<ActivityTitle>Title of the Activity</ActivityTitle>

</TopmostSubmenu>

I want to pull the value from the ActivityTitle>

Link to comment
Share on other sites

Hi,

then _StringBetween will be the easiest way. It is in the stable also!!!

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Mega, you're a smart guy...

What's faster, _StringBetween or StringRegExp?

Hi,

_StringBetween has an option to use RegExp. :-) Does this answer the question?

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Hi,

_StringBetween has an option to use RegExp. :-) Does this answer the question?

So long,

Mega

Right.. I took a look inside the String.au3 include and I concluded that using the StringRegExp option inside is very fast, although doing it manually may just save that little bit of extra time. Thanks, Mega.

Here it is, for those interested:

;==================================================================================================
; Function Name:        _StringBetween($sString, $sStart, $sEnd, $vCase, $iSRE)
;
; Parameters:           $sString:     The string to search
;                       $sStart:      The beginning of the string to find
;                       $sEnd:        The end of the string to find
;                       $vCase:       Case sensitive search:  Default or -1 = Not case sensitive
;                       $iSRE:        Choose whether to use StringRegExp or Regular Sting Manipulation to get the result
;                                     Default or -1:  Regular String Manipulation used (Non StringRegExp())
;
; Description:          Returns the string between the start search ($sStart) and the end search ($sEnd)
;
; Requirement(s)        AuotIt Beta 3.2.1.8 or higher
;
; Return Value(s)       On Success:    A 0 based array [0] contains the first found string
;                       On Failure:    @Error = 1: No inbetween string was found
;
; Author(s):            SmOke_N
;                       Thanks to Valik for helping with the new StringRegExp (?s)(?i) isssue
;==================================================================================================

Func _StringBetween($sString, $sStart, $sEnd, $vCase = -1, $iSRE = -1)
    If $iSRE = -1 Or $iSRE = Default Then
        If $vCase = -1 Or $vCase = Default Then
            $vCase = 0
        Else
            $vCase = 1
        EndIf
        Local $sHold = '', $sSnSStart = '', $sSnSEnd = ''
        While StringLen($sString) > 0
            $sSnSStart = StringInStr($sString, $sStart, $vCase)
            If Not $sSnSStart Then ExitLoop
            $sString = StringTrimLeft($sString, ($sSnSStart + StringLen($sStart)) - 1)
            $sSnSEnd = StringInStr($sString, $sEnd, $vCase)
            If Not $sSnSEnd Then ExitLoop
            $sHold &= StringLeft($sString, $sSnSEnd - 1) & Chr(1)
            $sString = StringTrimLeft($sString, $sSnSEnd)
        WEnd
        If Not $sHold Then Return SetError(1, 0, 0)
        $sHold = StringSplit(StringTrimRight($sHold, 1), Chr(1))
        Local $avArray[UBound($sHold) - 1]
        For $iCC = 1 To UBound($sHold) - 1
            $avArray[$iCC - 1] = $sHold[$iCC]
        Next
        Return $avArray
    Else
        If $vCase = Default Or $vCase = -1 Then
            $vCase = '(?i)'
        Else
            $vCase = ''
        EndIf
        Local $aArray = StringRegExp($sString, '(?s)' & $vCase & $sStart & '(.*?)' & $sEnd, 3)
        If IsArray($aArray) Then Return $aArray
        Return SetError(1, 0, 0)
    EndIf
EndFunc   ;==>_StringBetween
Link to comment
Share on other sites

Right.. I took a look inside the String.au3 include and I concluded that using the StringRegExp option inside is very fast, although doing it manually may just save that little bit of extra time. Thanks, Mega.

Here it is, for those interested:

;==================================================================================================
; Function Name:        _StringBetween($sString, $sStart, $sEnd, $vCase, $iSRE)
;
; Parameters:           $sString:     The string to search
;                       $sStart:      The beginning of the string to find
;                       $sEnd:        The end of the string to find
;                       $vCase:       Case sensitive search:  Default or -1 = Not case sensitive
;                       $iSRE:        Choose whether to use StringRegExp or Regular Sting Manipulation to get the result
;                                     Default or -1:  Regular String Manipulation used (Non StringRegExp())
;
; Description:          Returns the string between the start search ($sStart) and the end search ($sEnd)
;
; Requirement(s)        AuotIt Beta 3.2.1.8 or higher
;
; Return Value(s)       On Success:    A 0 based array [0] contains the first found string
;                       On Failure:    @Error = 1: No inbetween string was found
;
; Author(s):            SmOke_N
;                       Thanks to Valik for helping with the new StringRegExp (?s)(?i) isssue
;==================================================================================================

Func _StringBetween($sString, $sStart, $sEnd, $vCase = -1, $iSRE = -1)
    If $iSRE = -1 Or $iSRE = Default Then
        If $vCase = -1 Or $vCase = Default Then
            $vCase = 0
        Else
            $vCase = 1
        EndIf
        Local $sHold = '', $sSnSStart = '', $sSnSEnd = ''
        While StringLen($sString) > 0
            $sSnSStart = StringInStr($sString, $sStart, $vCase)
            If Not $sSnSStart Then ExitLoop
            $sString = StringTrimLeft($sString, ($sSnSStart + StringLen($sStart)) - 1)
            $sSnSEnd = StringInStr($sString, $sEnd, $vCase)
            If Not $sSnSEnd Then ExitLoop
            $sHold &= StringLeft($sString, $sSnSEnd - 1) & Chr(1)
            $sString = StringTrimLeft($sString, $sSnSEnd)
        WEnd
        If Not $sHold Then Return SetError(1, 0, 0)
        $sHold = StringSplit(StringTrimRight($sHold, 1), Chr(1))
        Local $avArray[UBound($sHold) - 1]
        For $iCC = 1 To UBound($sHold) - 1
            $avArray[$iCC - 1] = $sHold[$iCC]
        Next
        Return $avArray
    Else
        If $vCase = Default Or $vCase = -1 Then
            $vCase = '(?i)'
        Else
            $vCase = ''
        EndIf
        Local $aArray = StringRegExp($sString, '(?s)' & $vCase & $sStart & '(.*?)' & $sEnd, 3)
        If IsArray($aArray) Then Return $aArray
        Return SetError(1, 0, 0)
    EndIf
EndFunc   ;==>_StringBetween

Awesome, thanks so much guys.

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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