
Quote from jaydencone on December 23, 2022, 8:35 pmI'm trying to make my program read a server config but grab the server name values only, from a line of text. I need some help on grabbing a specific text, my code so far is:
FileRead "[PubDir]serverconfig.xml" "6" "[servername]"
SetObjectCaption "Text30" "[servername]"
Then I would like to set the caption to whatever the server name value is so people can see right away what their server name is set to.
Any suggestions or help much appreciated, thank you!
I'm trying to make my program read a server config but grab the server name values only, from a line of text. I need some help on grabbing a specific text, my code so far is:
FileRead "[PubDir]serverconfig.xml" "6" "[servername]"
SetObjectCaption "Text30" "[servername]"
Then I would like to set the caption to whatever the server name value is so people can see right away what their server name is set to.
Any suggestions or help much appreciated, thank you!
Uploaded files:
Quote from Gaev on December 24, 2022, 3:08 am@jaydencone
a) I am not sure why you are reading Line number 6 ... in the image, it looks like the information you want is in Line number 5 (including the blank line)
In any case, since this may change in the future, read the entire file into the variable
FileRead "[PubDir]serverconfig.xml" "All" "[xmlData]"b) Now parse on the (hopefully unique) string value of ServerName
StrParse "[xmlData]" "ServerName" "[serverNameLine]" "[junk]"... you will now have an array called [serverNameLine]. The second element (i.e. [serverNameLine2]) will contain all the text after the string value of ServerName.
c) Within this second array element, you are interested in the text after value=" ...
StrParse "[serverNameLine2]" "value=[#34]" "[serverNameToEndOfFile]" "[junk]"... note that [#34] is the code for the double quotes character.
d) you now want to separate the server name from the subsequent text (i.e. everything from "/> to the end of file ...
StrParse "[serverNameToEndOfFile2]" "![#34]/>" "[serverNameAndRestOfText]" "[junk]"... note the ! character is just so VisualNEOWin does not look at the / as a division symbol
e) The first array element (i.e. [serverNameAndRestOfText1]) now contains the name of your server ...
SetObjectCaption "Text30" "[serverNameAndRestOfText1]"Please note that this script is not tested/verified as I do not have access to your serverconfig.xml file ... so be forewarned about possible typos.
a) I am not sure why you are reading Line number 6 ... in the image, it looks like the information you want is in Line number 5 (including the blank line)
In any case, since this may change in the future, read the entire file into the variable
FileRead "[PubDir]serverconfig.xml" "All" "[xmlData]"
b) Now parse on the (hopefully unique) string value of ServerName
StrParse "[xmlData]" "ServerName" "[serverNameLine]" "[junk]"
... you will now have an array called [serverNameLine]. The second element (i.e. [serverNameLine2]) will contain all the text after the string value of ServerName.
c) Within this second array element, you are interested in the text after value=" ...
StrParse "[serverNameLine2]" "value=[#34]" "[serverNameToEndOfFile]" "[junk]"
... note that [#34] is the code for the double quotes character.
d) you now want to separate the server name from the subsequent text (i.e. everything from "/> to the end of file ...
StrParse "[serverNameToEndOfFile2]" "![#34]/>" "[serverNameAndRestOfText]" "[junk]"
... note the ! character is just so VisualNEOWin does not look at the / as a division symbol
e) The first array element (i.e. [serverNameAndRestOfText1]) now contains the name of your server ...
SetObjectCaption "Text30" "[serverNameAndRestOfText1]"
Please note that this script is not tested/verified as I do not have access to your serverconfig.xml file ... so be forewarned about possible typos.

Quote from jaydencone on December 24, 2022, 8:18 pmThanks a lot! This works exactly how I wanted it to
Thanks a lot! This works exactly how I wanted it to