FMS

XML search get change settings.

31 posts in this topic

#1 ·  Posted (edited)

Hello ,

I've the following problem and hope somebody can push me in the right direction or have a good example on how to do it.
The problem is :I want to search / select / change /check a XML setting in a XML file.

The example XML file is as following :

<Configuration>
  <Categories>
    <Category Name="default">
      <SubCategories>
        <SubCategory Name="defaultsettings">
          <Settings>
            <Setting Name="machinename" TypeName="System.String" Value="defaultname" />
            <Setting Name="cpuspeed" TypeName="System.String" Value="false" />
            <Setting Name="cmptemp" TypeName="System.String" Value="false" />
            <Setting Name="cmpspeed_set" TypeName="System.String" Value="" />
            <Setting Name="cmptemp_set" TypeName="System.String" Value="" />
          </Settings>
        </SubCategory>
      </SubCategories>
    </Category>
    <Category Name="settings">
      <SubCategories>
        <SubCategory Name="comp1">
          <Settings>
            <Setting Name="machinename" TypeName="System.String" Value="comp1" />
            <Setting Name="cpuspeed" TypeName="System.String" Value="true" />
            <Setting Name="cmptemp" TypeName="System.String" Value="false" />
            <Setting Name="cmpspeed_set" TypeName="System.String" Value="12" />
            <Setting Name="cmptemp_set" TypeName="System.String" Value="" />
          </Settings>
        </SubCategory>
        <SubCategory Name="comp2">
          <Settings>
            <Setting Name="machinename" TypeName="System.String" Value="comp2" />
            <Setting Name="cpuspeed" TypeName="System.String" Value="false" />
            <Setting Name="cmptemp" TypeName="System.String" Value="true" />
            <Setting Name="cmpspeed_set" TypeName="System.String" Value="" />
            <Setting Name="cmptemp_set" TypeName="System.String" Value="9" />
          </Settings>
        </SubCategory>
      </SubCategories>
    </Category>
  </Categories>
</Configuration>

In this XML file I want to :

-search if subcategory whit the name "comp3" exists
-if exist change of setting "cpuspeed" value to false
-if not exist make a new subcategory "comp3" whit the default settings from subcategory "default settings"

what i have this far is :

Func xml_test1()
   Dim $return[0]
   Local $file = @ScriptDir & "\test.xml"
   FileOpen($file, $FO_READ)
   _FileReadToArray($file,$return)
   FileClose($file)
         msg("",$return[28])
         msg("",$return[29])
EndFunc
   
func xml_test2()
   Local $file = @ScriptDir & "\test.xml"
   Local $oXML = ObjCreate("Microsoft.XMLDOM")
;~    $oXML.load("D:\___BUILDS___\___SRMT___\test.xml")
   $oXML.load($file)
   
   $oOther= $oXML.SelectSingleNode("//Configuration/Categories/Category/SubCategories/SubCategory/Settings/Setting") ; or //other
   ConsoleWrite("$oOther.text=[" & $oOther.text & "]" & @CRLF)
EndFunc

i know it is not enough what I'm trying to do but I'm realy stuk in what to do next.
I've searched in the XML.udf but could not find in the examples what to do what i want to do.
The things what i found are about <settings>false</settings> writing style of XML and not the way I've the XML.
(or I'm reading it wrong)

Is there somebody who can help me on mine way or has a good example script?

Thanks in advanced
 

Edited by FMS

as finishing touch god created the dutch

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

11 hours ago, FMS said:

-search if subcategory whit the name "comp3" exists

$oMatches = $oXML.selectNodes("SubCategory[Name='comp3']")
If $oMatches.Length>0 Then
    ;1 or more matches
Else
    ;no matches
EndIf

 

11 hours ago, FMS said:

-if exist change of setting "cpuspeed" value to false

For $i=0 To $oMatches.Length-1
    $oMatches.Item($i).selectSingleNode(".//Setting[@Name='cpuspeed']").SetAttribute("Value", "False"); Using selectSingleNode due to expectation that it only appears once withing the match?
Next

 

11 hours ago, FMS said:

-if not exist make a new subcategory "comp3" whit the default settings from subcategory "default settings"

$oMatch = $oXML.selectSingleNode("//Category[@Name='default']//SubCategory[@Name='defaultsettings']")
$oNode = $oMatch.CloneNode( True )
$oNode.SetAttribute("Name", "comp3")
$oNode.selectSingleNode(".//Setting[@Name='cpuspeed']").SetAttribute("Value", "false")
$oMatch = $oXML.selectSingleNode("//Category[@Name='settings']/SubCategories")
$oMatch.AppendChild( $oNode )

MsgBox(0, "", $oXML.xml); showing the xml after changes

 

Now I'm a bit lazy, so i did not add much error checking... but you can check up on the documentation, should you need it:

DOM Reference

XPath Syntax

IXMLDOMElement Members

 

Let me know if you need further help, or this makes no sense to you :)

Edited by genius257

Share this post


Link to post
Share on other sites

hello,
 

thanks for the example script @genius257.
I think i got it (for a bit i must say)
I fiddeled something around whit it because it was indeed something rocky code :)
(strangly i got a error whish i don't understand - "Variable used without being declared. - > For $i=0 To $oMathes.Length-1")
But this variable was made a sentence before :
 

Local $file = @ScriptDir & "test.xml"
Local $oXML = ObjCreate("Microsoft.XMLDOM")
$oXML.load($file)
;-if exist change of setting "cpuspeed" value to false
$oMatches = $oXML.selectNodes("SubCategory[Name='comp3']")
If $oMatches.Length>0 Then
    ConsoleWrite("hit = 1 or more" & @CRLF)
Else
    ConsoleWrite("hit = 0" & @CRLF)
EndIf

;-if exist change of setting "cpuspeed" value to false

For $i=0 To $oMathes.Length-1
    $oMatches.Item($i).selectSingleNode(".//Setting[@Name='cpuspeed']").SetAttribute("Value", "False"); Using selectSingleNode due to expectation that it only appears once withing the match?
Next
ConsoleWrite("setting should be changed cpuspeed = False" & @CRLF)
;-if not exist make a new subcategory "comp3" whit the default settings from subcategory "default settings"

$oMatch = $oXML.selectSingleNode("//Category[@Name='default']//SubCategory[@Name='defaultsettings']")
$oNode = $oMatch.CloneNode( True )
$oNode.SetAttribute("Name", "comp3")
$oNode.selectSingleNode(".//Setting[@Name='cpuspeed']").SetAttribute("Value", "false")
$oMatch = $oXML.selectSingleNode("//Category[@Name='settings']/SubCategories")
$oMatch.AppendChild( $oNode )
ConsoleWrite("section comp3 should be present" & @CRLF)
MsgBox(0, "", $oXML.xml); showing the xml after changes

anyway ,
i made 2 functions for it whish i hope u can help me whit.
The first funcion is to change the variable
Here he din't find any but i know it's there, so i fiddled around whit the $LC_hits (nothing found this far:))
if it lays on this i dont know.
 

Func XML_change()
   Local $LC_XML_file = @ScriptDir & "LocalSettings_forum.xml"
   Local $LC_XML_obj = ObjCreate("Microsoft.XMLDOM")
   $LC_XML_obj.load($LC_XML_file)
;~    Local $LC_hits = $LC_XML_obj.selectNodes("//Configuration/Categories/Category/SubCategories/SubCategory[name='Initialization']")
;~    Local $LC_hits = $LC_XML_obj.selectNodes("SubCategory[name='comp1']")
   Local $LC_hits = $LC_XML_obj.selectNodes("//Configuration//Categories//Category[@name='default']//SubCategory[name='comp1']")
   If $LC_hits.length = 0 Then
      ConsoleWrite("hit = 0" & @CRLF)
   ElseIf $LC_hits.length = 1 Then
      ConsoleWrite("hit = 1 " & @CRLF)
      For $i = 0 To $LC_hits.length - 1
         $LC_hits.Item($i).SelectSingleNode(".//Setting[@name='PosId']").SetAttribute("Value","1")
      Next
      ConsoleWrite("value should be changed" & @CRLF)
   ElseIf $LC_hits.length > 1 Then
      ConsoleWrite("hit = more then 1" & @CRLF)
   EndIf
EndFunc

The second function i made is to search and make
here i get an error " The requested action with this object has failed." -> ""Local $LC_XML_node = $LC_hit.CloneNode( True )"
and possibly also that he cant find even if it exist.

Func XML_search_or_make()
   Local $LC_XML_file = @ScriptDir & "LocalSettings_forum.xml"
   Local $LC_XML_obj = ObjCreate("Microsoft.XMLDOM")
   $LC_XML_obj.load($LC_XML_file)
;~    Local $LC_hits = $LC_XML_obj.selectNodes("//Configuration/Categories/Category/SubCategories/SubCategory[name='Initialization']")
   Local $LC_hits = $LC_XML_obj.selectNodes("SubCategory[name='comp3']")
   If $LC_hits.length = 0 Then
      ConsoleWrite("hit = 0" & @CRLF)
      Local $LC_hit = $LC_XML_obj.SelectSingleNode("//Category[@name='default']//SubCategory[@name='defaultsettings']")
      Local $LC_XML_node = $LC_hit.CloneNode( True )
      $LC_XML_node.SetAttribute["Name","Comp3"]
      $LC_XML_node.selectSingleNode(".//Setting[@name='cpuspeed']".SetAttribute("Value","false")
      $LC_hit = $LC_XML_obj.selectSingleNode("//Category[@name='settings']/Subcategories")
      $LC_hit.AppendChild( $LC_XML_node )
      MsgBox(0,"",$LC_XML_obj.xml)
   ElseIf $LC_hits.length = 1 Then
      ConsoleWrite("hit = 1" & @CRLF)
   ElseIf $LC_hits.length > 1 Then
      ConsoleWrite("hit = more then 1" & @CRLF)
   EndIf
EndFunc

Could somebody help whit this?

PS. Are there any includes i need for all this?

Thanks in advanced.

 


 


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites
5 minutes ago, FMS said:

(strangly i got a error whish i don't understand - "Variable used without being declared. - > For $i=0 To $oMathes.Length-1")

Sorry, that's my mistake :sweating:

I mispelled a variable in my second answer:

$oMathes

should be:

$oMatches

I will edit it in the post above right away :>

 

7 minutes ago, FMS said:

here i get an error " The requested action with this object has failed." -> ""Local $LC_XML_node = $LC_hit.CloneNode( True )"

That's what i was talking about with the error handling i did not do much of. "SelectSingleNode" will return a null object, if no match was found, whereas the selectNodes return a collection you can measure the length of. So the error is the result of you trying to call a function that does not exist in a null object.

 

11 minutes ago, FMS said:

PS. Are there any includes i need for all this?

For my examples? No.

Share this post


Link to post
Share on other sites

 lol I din't find that misspelling :S.
But i must say I'm a little lost in what you say.....
I tried to correct it in the code but dont know how to start.
Could u help me correct the 2 functions?
Or did you mean the code i've written will never work?
 


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

20 minutes ago, FMS said:

Could u help me correct the 2 functions?

I'll give it a look :)

Edit:

Could you post the xml, if it's different than the original?

Edited by genius257

Share this post


Link to post
Share on other sites

So I've added some comments explaining some of the errors.

But mostly it's just comes down to the fact that you need to be case specific so something like "Subcategories" would fail, but "SubCategories" would work

Func XML_change()
;~    Local $LC_XML_file = @ScriptDir & "LocalSettings_forum.xml"
   Local $LC_XML_file = @ScriptDir & "test.xml"
   Local $LC_XML_obj = ObjCreate("Microsoft.XMLDOM")
   $LC_XML_obj.load($LC_XML_file)
;~    Local $LC_hits = $LC_XML_obj.selectNodes("//Configuration/Categories/Category/SubCategories/SubCategory[name='Initialization']")
;~    Local $LC_hits = $LC_XML_obj.selectNodes("SubCategory[name='comp1']")
   Local $LC_hits = $LC_XML_obj.selectNodes("//Configuration//Categories//Category[@name='default']//SubCategory[name='comp1']")
   If $LC_hits.length = 0 Then
      ConsoleWrite("hit = 0" & @CRLF)
   ElseIf $LC_hits.length = 1 Then
      ConsoleWrite("hit = 1 " & @CRLF)
      For $i = 0 To $LC_hits.length - 1
         $LC_hits.Item($i).SelectSingleNode(".//Setting[@name='PosId']").SetAttribute("Value","1")
      Next
      ConsoleWrite("value should be changed" & @CRLF)
   ElseIf $LC_hits.length > 1 Then
      ConsoleWrite("hit = more then 1" & @CRLF)
   EndIf
EndFunc
Func XML_search_or_make()
;~    Local $LC_XML_file = @ScriptDir & "LocalSettings_forum.xml"
   Local $LC_XML_file = @ScriptDir & "\test.xml"
   Local $LC_XML_obj = ObjCreate("Microsoft.XMLDOM")
   $LC_XML_obj.load($LC_XML_file)
;~    Local $LC_hits = $LC_XML_obj.selectNodes("//Configuration/Categories/Category/SubCategories/SubCategory[name='Initialization']")
   Local $LC_hits = $LC_XML_obj.selectNodes("SubCategory[name='comp3']")
   If $LC_hits.length = 0 Then
      ConsoleWrite("hit = 0" & @CRLF)
      Local $LC_hit = $LC_XML_obj.selectNodes("//Category[@Name='default']//SubCategory[@Name='defaultsettings']");the @Name must be case specific
      If Not ($LC_hit.Length>0) Then Return; Escape the function if no match is found
      Local $LC_XML_node = $LC_hit.Item(0).CloneNode( True )
;~       $LC_XML_node.SetAttribute["Name","Comp3"]; This should be called with parenthesis, not square brackets ^^'
      $LC_XML_node.SetAttribute("Name","Comp3")
;~       $LC_XML_node.selectSingleNode(".//Setting[@name='cpuspeed']".SetAttribute("Value","false"); you are missing a parenthesis
      $LC_XML_node.selectSingleNode(".//Setting[@Name='cpuspeed']").SetAttribute("Value","false")
      $LC_hit = $LC_XML_obj.selectSingleNode("//Category[@Name='settings']/SubCategories"); Subcategories should be SubCategories
      $LC_hit.AppendChild( $LC_XML_node )
      MsgBox(0,"",$LC_XML_obj.xml)
   ElseIf $LC_hits.length = 1 Then
      ConsoleWrite("hit = 1" & @CRLF)
   ElseIf $LC_hits.length > 1 Then
      ConsoleWrite("hit = more then 1" & @CRLF)
   EndIf
EndFunc

Sorry if i didn't remove all my garbage lines for debugging, I'm off to bed for now :)

Share this post


Link to post
Share on other sites

Thnx @genius257 I got the making part of the unknown "comp3"

unfortanyl i dont think the searching part in "change" function is working.

or is there something i dint see?

sorry to ask again but could you look again?


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites
1 hour ago, FMS said:

unfortanyl i dont think the searching part in "change" function is working.

Well

Local $LC_hits = $LC_XML_obj.selectNodes("//Configuration//Categories//Category[@name='default']//SubCategory[name='comp1']")

Should be

Local $LC_hits = $LC_XML_obj.selectNodes("//Configuration//Categories//Category[@Name='default']//SubCategory[@Name='comp1']")

 

I hope you noticed that yourself, and yes i know that's my mistake :)

Second, the xml you posted, I test with does not have anything that would match your query, so it's hard to know if the function succeeds or not.

That's why i said:

On 10/9/2016 at 0:04 AM, genius257 said:

Could you post the xml, if it's different than the original?

 

Share this post


Link to post
Share on other sites

thank you very mush @genius257 , everything is working fine now :)
And no i din't find that typo :S it's mine dyslectia playing around whit me :)

Also I've learned some new things now, many thanks for that.
The final thing I cant work out is tho exaly write it to the XML file :)

I see it now changed in the :

MsgBox(0,"",$LC_XML_obj.xml)

But not in the file itself :S , I think it is a noobisch question but working whit XML is a new thing for me :)
Is there a special function to write it back to the XML itself?

 


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

I'm happy everyting is working :)

18 minutes ago, FMS said:

Is there a special function to write it back to the XML itself?

Yes and no :sweating:

It's not just one function, as you will have to overwrite the entire output in the file.

So something like:

$hFile = FileOpen(@ScriptDir & "\test.xml", 2);$FO_OVERWRITE
FileWrite($hFile, $LC_XML_obj.xml)
FileClose($hFile)

I would suggest looking into the help files and add error checking, if you wish to avoid problems. ^_^

They may end up wasting countless hours on debugging (i have that problem a lot :P)

Edited by genius257

Share this post


Link to post
Share on other sites

:lmao:rofl , no that can't be it.....
Stupid of me i din't think of doing that, i thought it was mush harder than that.
But what do you mean whit error checking on this 3 line of code?
maybe i don't understand it right but do u mean only check on fileopen , fileclose and filewrite?
Or do you mean if in the $LC_XML.obj is changed what i want to change?

 


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites
Just now, FMS said:

But what do you mean whit error checking on this 3 line of code?

FileOpen may fail for various reasons, i imagine FileWrite is also worth checking, just in case. FileClose however don't need any error checking.

It's just a precaution, to avoid data not being saved before you close down the program, thinking everything is dandy ^_^

Share this post


Link to post
Share on other sites

o is that all :)
that's what i always do but thank you for pointing out :)
(even i check on fileclose , why i should't i don't now)
I probaly check everything i do i must say.
But final question i've got on mine mind if you are up for that.
Do i need also to properly dispose of the $LC_XML_obj because it's now loaded in ?
Or because it's locale in the function it's cleaning up itself?

That was mine final question , many thanks for helping me around this subject.
10.000 points for grifindor!


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

12 minutes ago, FMS said:

Do i need also to properly dispose of the $LC_XML_obj because it's now loaded in ?
Or because it's locale in the function it's cleaning up itself?

Well honestly I'm not 100% sure, i believe the local variables gets cleaned up by the garbage collector when the function ends. Personally i just leave it like that, but that question might be worth searching for in the forum, i believe I've seen it discussed.

12 minutes ago, FMS said:

That was mine final question , many thanks for helping me around this subject.
10.000 points for grifindor!

It was fun for me too :)
Haha! Why thank you :lol:

Edited by genius257
1 person likes this

Share this post


Link to post
Share on other sites

humm I'm very sorry to disturb you again @genius257 but when i thought i got it  , a error was lurking around :>
I hope u can help me once more because i realy don't understand why it gives me this error.
When I was making this "Beta" function :

Func XML_change();hidden button 1
   Local $LC_XML_file = @ScriptDir & "\forum.xml"
   Local $LC_XML_obj = ObjCreate("Microsoft.XMLDOM")
   $LC_XML_obj.load($LC_XML_file)
   Local $LC_hits = $LC_XML_obj.selectNodes("//Configuration//Categories//Category[@Name='settings']//SubCategory[@Name='comp1']")
;~    MsgBox(0,"",$LC_XML_obj.xml)
   If $LC_hits.length = 0 Then
      ConsoleWrite("hit = 0" & @CRLF)
   ElseIf $LC_hits.length = 1 Then
      ConsoleWrite("hit = 1" & @CRLF)
      For $i = 0 To $LC_hits.length - 1
         $LC_hits.Item($i).SelectSingleNode(".//Setting[@name='cmptemp_set']").SetAttribute("Value","1")
      Next
      MsgBox(0,"",$LC_XML_obj.xml)
   ElseIf $LC_hits.length > 1 Then
      ConsoleWrite("hit = more then 1" & @CRLF)
   EndIf
EndFunc

I did got this error :

$LC_hits.Item($i).SelectSingleNode(".//Setting[@name='cmptemp_set']").SetAttribute("Value","1")
$LC_hits.Item($i).SelectSingleNode(".//Setting[@name='cmptemp_set']")^ ERROR

At first I thought it was the <settings> between <subcategory> and <setting> , but in no case it got me another error then this.
If I'm not mistaking it can't find the attribute value? (but can find //SubCategory[@Name='comp1'])


 


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites
9 hours ago, FMS said:

I did got this error :

$LC_hits.Item($i).SelectSingleNode(".//Setting[@name='cmptemp_set']").SetAttribute("Value","1")
$LC_hits.Item($i).SelectSingleNode(".//Setting[@name='cmptemp_set']")^ ERROR

 

Yeah no match is returned from you query.

I bet if you notice the attribute name is all lower case, you find your answer. :)

hint:

@name

 

Share this post


Link to post
Share on other sites
10 hours ago, FMS said:

I did got this error :

$LC_hits.Item($i).SelectSingleNode(".//Setting[@name='cmptemp_set']").SetAttribute("Value","1")
$LC_hits.Item($i).SelectSingleNode(".//Setting[@name='cmptemp_set']")^ ERROR

 

You can not use such long onliner, you should pares it for each method to separate lines and check for errors  after each line.


Wondering who uses AutoIT and what it can be used for ?


ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button:

Spoiler

Last update: 2017-05-03
Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAPPOP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF * WinSCP UDF *

My contribution to others projects: * _sql.au3 UDF  *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

 

Share this post


Link to post
Share on other sites

pfff was that it the uppercase N :)
thanks, all works fine (again) @genius257

also thanks for pointing that out @mLipok , but i must say I'm rather new to XML searches and changes.
And realy don't know where you are talking about.
Could u show me what u mean>?


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites
$step1 = $LC_hits.Item($i)
If @error ....
$step2 = $step1.SelectSingleNode(".//Setting[@name='cmptemp_set']")
If @error ....
$step3 = $step2.SetAttribute("Value","1")
If @error ....

 


Wondering who uses AutoIT and what it can be used for ?


ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button:

Spoiler

Last update: 2017-05-03
Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAPPOP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF * WinSCP UDF *

My contribution to others projects: * _sql.au3 UDF  *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

 

Share this post


Link to post
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

  • Similar Content

    • Simpel
      By Simpel
      Hi. I'm trying to write a xml. Here is my code:
      #include <_XMLDomWrapper.au3> #include <Date.au3> Global $g_sXMLFileName Global $g_sDestPath = @DesktopDir & "\" Global $g_sReturnedBID = "A10829" _makeXML() _AddXML(1, "A10829_Thomas/wav/T001.wav") _AddXML(2, "A10829_Thomas/wav/T002.wav") Exit Func _makeXML() Local $sXMLtime = StringReplace(StringReplace(StringReplace(_NowCalc()," ","_"),":","-"),"/","-") ; in yyyy-mm-dd_hh-mm-ss $g_sXMLFileName = $g_sDestPath & $g_sReturnedBID & "_" & "EB-Ton-Upload" & "_" & $sXMLtime & ".xml" _XMLCreateFile($g_sXMLFileName, "gemagvl", 1,1) _XMLFileOpen($g_sXMLFileName) EndFunc Func _AddXML($iCount, $sDateiname) _XMLCreateRootNodeWAttr("row", "count", $iCount, "") _XMLCreateChildNode("//row", "picklistenname", $g_sReturnedBID & "_EB-Ton-Upload") _XMLCreateChildNode("//row", "picklisteninfo") _XMLCreateChildNode("//row", "bid", $g_sReturnedBID) _XMLCreateChildNode("//row", "audiodateiname", $sDateiname) _XMLCreateChildNode("//row", "titel", StringTrimRight(StringTrimLeft($sDateiname, 7), 4)) _XMLCreateChildNode("//row", "interpret", "EB") _XMLCreateChildNode("//row", "quelle", "Ton") EndFunc It returns:
      <?xml version="1.0" encoding="UTF-8"?><gemagvl> <row count="1"> <picklistenname>A10829_EB-Ton-Upload</picklistenname> <picklisteninfo/> <bid>A10829</bid> <audiodateiname>A10829_Thomas/wav/T001.wav</audiodateiname> <titel>Thomas/wav/T002</titel> <interpret>EB</interpret> <quelle>Ton</quelle> <picklistenname>A10829_EB-Ton-Upload</picklistenname> <picklisteninfo/> <bid>A10829</bid> <audiodateiname>A10829_Thomas/wav/T002.wav</audiodateiname> <titel>Thomas/wav/T003</titel> <interpret>EB</interpret> <quelle>Ton</quelle> </row> <row count="2"> <picklistenname>A10829_EB-Ton-Upload</picklistenname> <picklisteninfo/> <bid>A10829</bid> <audiodateiname>A10829_Thomas/wav/T002.wav</audiodateiname> <titel>Thomas/wav/T003</titel> <interpret>EB</interpret> <quelle>Ton</quelle> </row> </gemagvl> But it should return:
      <?xml version="1.0" encoding="UTF-8"?><gemagvl> <row count="1"> <picklistenname>A10829_EB-Ton-Upload</picklistenname> <picklisteninfo/> <bid>A10829</bid> <audiodateiname>A10829_Thomas/wav/T001.wav</audiodateiname> <titel>Thomas/wav/T002</titel> <interpret>EB</interpret> <quelle>Ton</quelle> </row> <row count="2"> <picklistenname>A10829_EB-Ton-Upload</picklistenname> <picklisteninfo/> <bid>A10829</bid> <audiodateiname>A10829_Thomas/wav/T002.wav</audiodateiname> <titel>Thomas/wav/T003</titel> <interpret>EB</interpret> <quelle>Ton</quelle> </row> </gemagvl> The second inserted nodes are double. How will it be going right?
      Regards, Conrad
    • rootx
      By rootx
      I need help to read in a loop the DVD id child and subchild. Thx
      Example...
      DVD001 - PAL - EN,FR,DE,ES,IT and filter the right title & descri language.  I tried with $oXML.SelectSingleNode but without success
      <?xml version="1.0" encoding="UTF-8"?> <datafile xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="mydvd.xsd"> <dvd name="My dvd title"> <id>DVD001</id> <region>PAL</region> <languages>EN,FR,DE,ES,IT</languages> <locale lang="EN"> <title>title en</title> <descri>descri en</descri> </locale> <locale lang="FR"> <title>title fr</title> <descri>descri fr </descri> </locale> <locale lang="DE"> <title>title de</title> <descri>descri de </descri> </locale> <locale lang="ES"> <title>title es</title> <descri>descri es</descri> </locale> <locale lang="IT"> <title>title it</title> <descri>descri it</descri> </locale> </dvd> <dvd name="My dvd title 2"> <id>DVD002</id> <region>USA</region> <languages>EN</languages> <locale lang="EN"> <title>title en</title> <descri>descri en</descri> </locale> </dvd> </datafile> #include <File.au3> $xml = @ScriptDir&"\test.xml" Local $oXML = ObjCreate("Microsoft.XMLDOM") $oXML.load($xml) $id = $oXML.SelectNodes("//dvd") For $ids In $id ConsoleWrite($ids.text &@CRLF) Next  
    • vikashbitm2010
      By vikashbitm2010
      Hi all,
      I want to return string from autoit script to the python code.
      Autoit:
      Exit("22 FE 45") -> not working
      Exit(1) -> Working
      Exit(0) -> Working
      python:
      import os
      res=os.system(autoitmine.exe)
      print "res",res
      I got some hint of @ExitCode macro, but dont know how to use it to get the string in python variable 'res'.
      Please resolve this issue for me if anyone knows about this.
       
    • QuickWhiteWolf
      By QuickWhiteWolf
      Hi everyone,
       
      I was previously a member of this forum under the username Wombat. It's been years and multiple email accounts closed since then so I decided to start fresh and take a moment to thank you all... (Admins/Mods let me know if we need to discuss this...)
       
      I started programming with AutoIT while working as a scrap catcher for a machine that chopped scrap into pieces for easier moving, I learned styles and gained strengths from some of the best members on this forum by reverse engineering their code. I gained the confidence of our IT manager by making a boast that I could write an application to replace a p.o.s. cobalt based app we were using on the floor at that time, needless to say I was way in over my head but he saw that I had potential and I luckily had built several other apps on the side that were of equal or greater value to the company. I've been working as help-desk for the past 3 years and writing software as well to facilitate the help desk and solve recurring issues with our users. I was given an office and moved out of help-desk about a year ago, after 5 years of hard work I've actually landed the title of Jr. Developer moving into mid level title/pay this year! The company has already set out an improvement path that sees me with 4 certs and a bachelors in 4 more years making great money. Before this I had only ever worked at gas stations, fast food and manual labor jobs. If you're ever worried about your life, want something more, or just want a change you can do it. It's not easy, not at all, but it's possible and software programming is a very rewarding field if you like to make things and see how others interact with them.

      I utilized AutoIT to bring a company into the twenty-first century, away from paper trails and sticky notes improving the quality of life for the employees on the floor (where I started before learning AutoIT). I was given the go ahead to purchase visual studio and I learned VB.Net and built an awesome piece of Zebra labeling software (Utilizing ZPL code translated froma graphical editor) for our shipping department. Now I'm diving head first into C# and we have another programmer on board as we move on to MS Team Services and begin to tackle a sweet new project involving real time awareness of our product on the factory floor utilizing RFID and windows 10 tablets.

      That's a long way to come in just 4 years, and I couldn't have done it without the gigantic heart this community has and the mentorship provided for people looking to get into programming.

      So from the bottom of my heart, with immense respect.... Thank you so much AutoIT community
    • Valnurat
      By Valnurat
      Hi.
      How do you find all printers installed on a computer?
      I'm searching for the name, location and port