WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: spl on March 17, 2025, 11:24:23 AM

Title: OT: Copilot makes a slight mistake
Post by: spl on March 17, 2025, 11:24:23 AM
Having enjoyed the thread for fun with xml, reminded me of the old days in WB when a topic was broached by multiple participants all until the code was adequate. Maybe now, AI is the answer. So I asked copilot "Give me a Winbatch script to parse xml nodes"

AddExtender("WWInt51i.DLL", 0, 0) ; Load the XML extender

; Define the XML content or file path
xmlContent = `"<root>
                  <node1>Keep Me</node1>
                  <node2>Remove Me</node2>
                  <node3>Keep Me Too</node3>
               </root>"`

; Load the XML into the extender
xmlDoc = XMLLoadString(xmlContent)

; Find and remove the nodes you don't want
while XMLFindElement(xmlDoc, "node2")
    XMLRemoveElement(xmlDoc, "node2")
endwhile

; Save or output the modified XML
newXmlContent = XMLGetString(xmlDoc)
Message("Modified XML", newXmlContent)

; Clean up
XMLRelease(xmlDoc)


?????????????????
Title: Re: OT: Copilot makes a slight mistake
Post by: td on March 17, 2025, 01:34:56 PM
I guess you would need to perform some model training...
Title: Re: OT: Copilot makes a slight mistake
Post by: spl on March 18, 2025, 02:46:49 AM
Quote from: td on March 17, 2025, 01:34:56 PMI guess you would need to perform some model training...

Nah! Just need to find where the Extender is hiding [where is a good imogi when you need one]
Title: Re: OT: Copilot makes a slight mistake
Post by: td on March 18, 2025, 09:03:42 AM
Good luck with that. But there is always the alternative of you writing one for all of us.
Title: Re: OT: Copilot makes a slight mistake
Post by: spl on March 18, 2025, 11:01:39 AM
Quote from: td on March 18, 2025, 09:03:42 AMGood luck with that. But there is always the alternative of you writing one for all of us.

Hey AI, can you write me a 32/64 bit Extender for manipulating XML in Winbatch?
Title: Re: OT: Copilot makes a slight mistake
Post by: td on March 18, 2025, 01:26:56 PM
Good luck with that too.
Title: Re: OT: Copilot makes a slight mistake
Post by: JTaylor on March 21, 2025, 08:51:06 AM
Quote from: spl on March 18, 2025, 11:01:39 AMHey AI, can you write me a 32/64 bit Extender for manipulating XML in Winbatch?


I already did ;-)
Title: Re: OT: Copilot makes a slight mistake
Post by: td on March 21, 2025, 10:23:41 AM
There you go. Problem solved and, at least I hope, no AI needed.
Title: Re: OT: Copilot makes a slight mistake
Post by: guuzendesu on April 25, 2025, 06:21:02 PM
I don't have any idea when it comes to XML, but how did Grok do?

; WinBatch script to parse XML nodes

; Define the XML file path
cXML = "example.xml"

; Check if the file exists
If ! FileExist(cXML) Then
    Message("Error", "XML file not found: " : cXML)
    Exit
EndIf

; Create the DOM object
oDOM = ObjectOpen("Msxml2.DOMDocument.4.0")
oDOM.async = @false
oDOM.Load(cXML)

; Check for parse errors
If oDOM.parseError.errorCode != 0 Then
    Message("Error", "Failed to load XML: " : oDOM.parseError.reason)
    ObjectClose(oDOM)
    Exit
EndIf

; Select the nodes, for example, all <node> under <root>
oNodes = oDOM.SelectNodes("/root/node")

; Loop through the nodes and display their text
For i = 0 To (oNodes.length - 1)
    elem = oNodes.Item(i)
    Message("Node value", elem.Text)
Next

; Close the DOM object
ObjectClose(oDOM)
Exit