Welcome! Log In Create A New Profile


Reading an XML file

Posted by SteveSitas 
Reading an XML file
March 20, 2021 12:43PM
I am trying to read an XML file with the help of an XSD file (included in my project).
I can do everything manually with XML node(s) but I can't do it with the help of an XSD !!!

Here is how the XML files looks like (very simple description):

.... various nodes

.... various nodes

.... various nodes


and here is how my code looks like (requestDoc-v1_0_2 is the XSD schema):

sFileName = "myFile.xml"
sResultXMLDocument is xmlDocument <description="requestDoc-v1_0_2"> = XMLOpen(sFileName,fromFile)
NODEInvoice is xmlNode <description="requestDoc-v1_0_2.RequestedDoc.invoicesDoc">

FOR EACH NODEInvoice OF sResultXMLDocument

Now I want to LOOP through all the <invoice> nodes - but It always goes ONE time through the loop
I have also done the following, but with no luck ...

NODEInvoice is xmlNode <description="requestDoc-v1_0_2.RequestedDoc.invoicesDoc.invoice">
NODEInvoice is xmlNode <description="requestDoc-v1_0_2.RequestedDoc.invoicesDoc">
NODEInvoice is xmlNode <description="requestDoc-v1_0_2.RequestedDoc">

Any Ideas?

Steven Sitas

Edited 1 time(s). Last edit at 03/20/2021 02:43PM by SteveSitas.
Re: Reading an XML file
March 21, 2021 10:56AM

My problem with the above code is that I cannot find a valid FOR EACH syntax when an XML node (NODEInvoice) uses a syntax with the <description =...
It works fine when NODEInvoice is xmlNode (the simple syntax), but then I don't have ANY kind of autocompletion with the xmlNode...

Steven Sitas
Re: Reading an XML file
March 21, 2021 02:25PM
Hi Steven

My experience is that WX doesn't handle definition files very well for JSON and XML (xsd).
Using sample files with real data works much better.
That is pretty crappy compared to e.g. VS but you could try loading in a sample XML file instead of the definition (XSD).

Hope it helps you out.

Just my 2 cents

Re: Reading an XML file
March 22, 2021 10:31AM
Hi Peter,
After many tries, I finally found how to LOOP/Read an XML file with XMLnode(s) and XSD(s).
The help (as most of the time) is not very helpful and I am starting to think that the English version of the help is produced "automatically" ..

And of course, there is NO example to show the above.
Here is what works for me (with Autocompletion).

1. Lets say that we have an XSD (rDoc-v1.0) with a node "invoice".
This node can be ANYWHERE in the XSD but you need to write down its exact path, like in the following:

sResultXMLDocument is xmlDocument <description="rDoc-v1.0">
invoice is xmlNode <description="rDoc.InvoicesDoc.invoice">

* Important: Note that the Root of the XML is "rDoc" _and_ NOT "rDoc-v1.0"
Always check this ...

2. Do the following FOR EACH (or FOR ALL)

FOR EACH invoice OF sResultXMLDocument.rDoc.InvoicesDoc ON invoice
// in here now we have autocompletion on "invoice" and NO missing node errors ...

Steven Sitas

Edited 1 time(s). Last edit at 03/22/2021 11:20AM by SteveSitas.
Re: Reading an XML file
March 22, 2021 10:57AM
Hey Steven

Glad you found your way around.
Thank you for sharing your knowledge in this area ! Highly appreciated.

I'm sure this will be helpful for me too and will try the same with JSON definition files instead os sample files to see if that works the same way.



Your Email:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.