Page 1 of 1 1
Topic Options
#214237 - 2023-06-23 02:31 PM XML Load error
Robdutoit Offline
Hey THIS is FUN
***

Registered: 2012-03-27
Posts: 363
Loc: London, England
This is not a big issue and I have "resolved" it by defining it as a variable. But I am curious as to why it is doing this - I am not sure if it is a Kixtart issue or a parsing issue with XML syntax?

 Code:
      $XML = CreateObject("Microsoft.XMLDOM")
      $XML.Load($Filename)


When you run $xml.Load($FileName) it always outputs code -1 which suggests that it is either having a problem opening the file (which is not the case as the rest of the code works as expected) or there is a parsing error reading the file.

 Code:
      $XML = CreateObject("Microsoft.XMLDOM")
      $ = $XML.Load($Filename)


This works perfectly, or rather it is suppressing the output code. Normally we want to use $x = to suppress outputs like 0 for the addprinterconnection as we don't need to see it was successful. But in this case, there is obviously an error so it's outputting -1. I don't tend to use @error much.

I have uploaded the xml file to several xml validators and they do find syntax issues, but as I far as I can tell, the xml syntax is correct according to Microsoft - online and using a file created by Microsoft itself. The syntax issues may be more to do with a different library versions of xml or perhaps the xml online is more for html xml type files?

The xml files that I am working with are the Windows Libraries - which can be found in this folder - C:\Users\Username\AppData\Roaming\Microsoft\Windows\Libraries.

I am using Kixtart to load the custom Libraries that I have copied across to the Libraries folder to input the url relevant for that library. Works perfectly apart from this strange -1 output. As it does work, I see no value spending a lot of time on it, but I am curious as to why it's happening and whether this is a kixtart or xml issue.

Top
#214238 - 2023-06-24 11:45 PM Re: XML Load error [Re: Robdutoit]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Trying your code and adding "@SERROR ?" statements after the CreateObject and the XML.Load commands, I find that both report "The operation completed successfully.". The "-1" is most likely a returned "TRUE" value indicating that it successfully loaded the file.

Thus - it isn't an issue at all, either with Kix or with the XML object.

A function can return TWO values:
1. The Return Value. This is often the data that is the result of a function. For example - pass it "2", the function multiplies it by 4 and returns a value of "8". For functions that don't return "data", the return value is often a TRUE/FALSE indicating that the function had succeeded or not. This is often the opposite of the Return Code (or Status or Error code).
2. Return Code (or Status or Error code). This is the value returned by the Exit command. Exit 0 indicates success (and is often paired with a non-zero Return Value). An exit of non-zero indicates an error, and the Return Value would be zero if an error had occurred.

Not all functions that don't need to return data return a Return Value, but that's a good practice. It simplifies coding - such as:
 Code:
If $XML.Load($Filename)
  ; successful read - continue with the program
Else
  ; failure - look at the error code and determine if any recovery is possible
  'Failed to read ' + $Filename + ' Error reported: ' + @SERROR @CRLF
EndIf
This is a shortcut, eliminating the need to check the error code unless an error actually occurred.
_________________________
Actually I am a Rocket Scientist! \:D

Top
#214239 - 2023-06-25 11:50 AM Re: XML Load error [Re: Glenn Barnas]
Robdutoit Offline
Hey THIS is FUN
***

Registered: 2012-03-27
Posts: 363
Loc: London, England
Oh does the @serror actually say operation completed successfully. I did not try that as I misunderstood the example instructions to mean that I put my own error message in.

It is very unusual (as far as I am aware) to have -1 as a successful outcome! I would expect it to be 0. Oh well, mystery explained!

One of my jobs soon is to add a global @error, @serror to the entire sript as even Chatgpt says I need to add @error functionality in! I am just busy with other aspects of my coding at the moment, removing obsolete coding that is not being used anymore, using Chatgpt to optimise my existing coding - did wonders for my XML load script - two thirds of the original coding is gone!

But on the whole, my scripts work really well. When I did a complete of the code about 2 years ago, I really improved the flow of the script and removed a lot of duplicate files for each user group and thus duplicate coding. Now, I am just tweaking to the nth degree as I have time!

Top
#214240 - 2023-06-25 07:34 PM Re: XML Load error [Re: Robdutoit]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
You are confusing the Return VALUE with the Return CODE. The Return CODE is the error status and 0=Success, non-0=failure. The VALUE is the data returned. Some functions don't return any "data" so they (if well-written) will return the opposite of the CODE. Reread my example above. Without a return VALUE, I would need to examine the Return CODE every time to determine if the function was successful. By returning an inverted VALUE, I can simply test whether the the VALUE is true without checking the CODE. Thus, the code is checked only IF there's a failure and we need to determine what that failure was and if we can recover.

The Return VALUE can be any non-zero or non-null value to indicate success. Apps often return -1, scripts often return 1. Same result.
_________________________
Actually I am a Rocket Scientist! \:D

Top
#214241 - 2023-06-26 11:49 AM Re: XML Load error [Re: Glenn Barnas]
Robdutoit Offline
Hey THIS is FUN
***

Registered: 2012-03-27
Posts: 363
Loc: London, England
They do say any day you learn something is a day not wasted! Thank you. I wasn't massively worried about it as the library was working correctly, but I wanted to understand why I was seeing -1 for this.

Just out interest, Chatgpt suggested that I only use @error when developing code as nearly all the code I use would be writing to registry, so in general @error is not very useful for production systems. That is in general as usually a production code - everything is working! One or two bits of coding, I think it might make sense to keep the @error as printers etc get changed over time, even if the kixtart coding doesn't.

So I will review what @error coding I have, see where it makes sense to add the @error and where I can just get rid of it as my next job is to only output to the console what I don't mind an end user seeing. They don't see it anyway as the startup script is not visible to the end user and the logon script runs minimised. But I still would like to tidy up the output to only high level messages.

It helps to know about Return Value and Return Code in the context that I was seeing with the load xml files.

Top
#214244 - 2023-06-27 08:30 PM Re: XML Load error [Re: Robdutoit]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
In my opinion, it's a bit naive to expect code to always work in production. There's a reason there are try/catch methods in most programming languages.
Top
#214248 - 2023-06-28 12:18 AM Re: XML Load error [Re: ShaneEP]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
I agree, Shane!

We have close to 90 Kix-based apps in production on over 100,000 computers globally. We write our scripts to a very high standard, and check error status on everything, and STILL get caught with crashes when the environment changes, MS changes the rules (call methods) or an endpoint has some AV that blocks a system call but not the application. Our applications actually write telemetry data back to us if they encounter bad data, and we get notified if an application crashes so we can evaluate and improve the data and error handling.

You can't anticipate every possible condition, so checking the return code of your functions is essential to reliability. If ChatGPT is suggesting otherwise, it isn't as "intelligent" as it might seem. \:\)
_________________________
Actually I am a Rocket Scientist! \:D

Top
#214261 - 2023-07-18 03:16 PM Re: XML Load error [Re: Glenn Barnas]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11624
Loc: CA
I think many people believe that ChatGPT is a black-box designed to simply serve you up code.

You need to know the code basics on your own or it will not be able to help you much.
You describe and detail what you're looking for and the expected results. Then be prepared for it to provide code that is not production ready. That is where you the person comes in and critiques the code and offers suggestions for different methods or ideas. Then you work back and forth with ChatGPT to come to production level code. Be warned though that it is more than annoying at times as the larger and more complex the code gets, the harder it will be to work on it and it will need to post in 3, 4 or more smaller portions of code or it will truncated due to posting limits within the program.


Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 370 anonymous users online.
Newest Members
Timothy, Jojo67, MaikSimon, kvn317, kixtarts2025
17874 Registered Users

Generated in 0.103 seconds in which 0.077 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org