And the next step would be to place it in the xsd folder of the uar zip file.
Original Message:
Sent: 09-20-2024 09:49
From: Ingo Stiller
Subject: XML read and validation with xmltostruct
ad a) check out the article in the docu about workdir
If you are on windows and start you application by shortcut, the second line in the shorctcut properties is the workdir (I do have onyl a german environment, so I'm not sure how it is labeled :-) )
You can set also the workind directory by /dir=
ad b)
If you don't have specific namespaces just use 'targetnamespace'
<xs:schema targetNamespace="name_of_the_namespace" xmlns:xs="http://www.w3.org/2001/XMLSchema" >
The name is any thing you like, but it must match the name in the UF-SchemaList
Here is an example with the alias "h" for a namespace
<h:table>
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>
<f:table>
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>
------------------------------
Ingo Stiller
Aareon Deutschland GmbH
Original Message:
Sent: 09-20-2024 09:36
From: Jozef Prokopovic
Subject: XML read and validation with xmltostruct
a) write the XSD-File into the working-directory (on a harddrive)
which one is the working directory? the one where I start the application from?
b) check if the in the XML-File on top there is a line with your namespace
<xs:schema targetNamespace="name_of_the_namespace" xmlns:my_alias="name_of_the_namespace" xmlns:xs="http://www.w3.org/2001/XMLSchema" >
so the xml needs to contain this line? What is the Namespace? Can I just add random name for namespace? How the uniface will know that this namespace is the one where is the xsd file located?
the c and d section is clear.
------------------------------
Jozef Prokopovic
Uniface Community Edition Shared Account
US
Original Message:
Sent: 09-20-2024 09:13
From: Ingo Stiller
Subject: XML read and validation with xmltostruct
Just
a) write the XSD-File into the working-directory (on a harddrive)
b) check if the in the XML-File on top there is a line with your namespace
<xs:schema targetNamespace="name_of_the_namespace" xmlns:my_alias="name_of_the_namespace" xmlns:xs="http://www.w3.org/2001/XMLSchema" >
c) make a UIL (UnifAce-Item-List)
$1 =""
putitem/id $1,"NAMESPACE" ,"name_of_the_namespace"
putitem/id $1,"LOCATION" ,"name_of_the_XSD_file_on_a_drive.xsd"
d) call XmlToStruct:
xmlToStruct/full/validate/schema vy_STRUCT, vx_XML,$1
------------------------------
Ingo Stiller
Aareon Deutschland GmbH
Original Message:
Sent: 09-20-2024 08:43
From: Jozef Prokopovic
Subject: XML read and validation with xmltostruct
to be honest I am lost :) I found this text in help:
-
SchemaList-namespace and location of one or more schemas. For a single schema, SchemaList can be a file name, URL, or a Uniface index list. For multiple schemas, it must be a Uniface list of name-value pairs in the format:
so I was thinking that it is enough to enter the schema name and place it in the right location
------------------------------
Jozef Prokopovic
Uniface Community Edition Shared Account
US
Original Message:
Sent: 09-20-2024 08:04
From: Ingo Stiller
Subject: XML read and validation with xmltostruct
And a hint:
Namespaces and alias are no more than 'sound and smoke'
There is no technical reason to use a real URN, you can use "Hugo" and "Elisabeth" as names. you should also not rely on the fact that the aliases (<alias>+": "+<element_name>) are always provided as you think they are. If you find an alias, look in the schema definition, get the namespace name there and then use it in lookup tables or in the location statement to find the corresponding XSD description.
But be careful when writing with aliases. Not all recipients can handle the official way of arbitrary aliases and require very special aliases.
This is actually wrong, but what can you do if there is an authority or a large customer on the other side :-)
Ingo
------------------------------
Ingo Stiller
Aareon Deutschland GmbH
Original Message:
Sent: 09-20-2024 07:52
From: Ingo Stiller
Subject: XML read and validation with xmltostruct
BTW: this is the header of such XSD
Note the IMPORT instruction (if you have one), the filename must also include tilde here
<xs:schema elementFormDefault="qualified"
targetNamespace="urn:applname_xyz:xsd:gen.gen.01.20160501"
xmlns:appl="urn:applname_xyz:xsd:gen.gen.01.20160501"
xmlns:applt="urn:applname_xyz:xsd:types.all.01.20160501"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="urn:applname_xyz:xsd:types.all.01.20160501"
schemaLocation="~types.all.01.20160501.p11868.xsd" />
...
.
------------------------------
Ingo Stiller
Aareon Deutschland GmbH
Original Message:
Sent: 09-20-2024 07:47
From: Ingo Stiller
Subject: XML read and validation with xmltostruct
Hi Jozef
The last parameter is not a XSD-File/text but a schema list :-)
Here is my NameSpaceInfo itemlist which a helper compent returns me:
ALIAS=appl·;
NAMESPACE=urn:applname_xyz:xsd:gen.gen.01.20160501·;
LOCATION=~gen.gen.01.20160501.p11868.xsd·;
REF_NS_LST=!APPL*TYPES*ALL*01*20160501=ALIAS=applt·!·!·;
NAMESPACE=urn:applname_xyz:xsd:types.all.01.20160501·!·!·;
LOCATION=~types.all.01.20160501.p11868.xsd·;
ALIAS_LST=APPL=urn:applname_xyz:xsd:gen.gen.01.20160501·!·;
applt=urn:applname_xyz:xsd:types.all.01.20160501·;
UF_SCHEMA_LST=NAMESPACE=urn:applname_xyz:xsd:gen.gen.01.20160501·!·!·;
LOCATION=~gen.gen.01.20160501.p11868.xsd·!·;
NAMESPACE=urn:applname_xyz:xsd:types.all.01.20160501·!·!·;
LOCATION=~types.all.01.20160501.p11868.xsd·;
XSI_SCHEMALOCATION=urn:applname_xyz:xsd:gen.gen.01.20160501 ~gen.gen.01.20160501.p11868.xsd urn:applname_xyz:xsd:types.all.01.20160501 ~types.all.01.20160501.p11868.xsd
As we do have our own SOAP-interface with XML-payload in different versions and with nested namespaces, it loolk on first sight a litte bit scary.
UnifAce is not able do handle XSD inline/in memory, so the XSD-Files has to be writte to some place to the hard drive.
Our XSD-File do have the name as the schema plus a tilde in front (like othe temp files)
The UF_SCHEMA_LST is then to be taken as third parameter of
xmlToStruct/full/validate/schema vy_STRUCT, vx_XML,v_UF_SCHEMA_LST
Uniface interprets the XML and reads the namespace alias<->namespace assigment.
Then it loads the XSD by the location-string and does the validation
Ingo
------------------------------
Ingo Stiller
Aareon Deutschland GmbH
Original Message:
Sent: 09-20-2024 06:52
From: Jozef Prokopovic
Subject: XML read and validation with xmltostruct
Yes, I would like to but do you have any example how to use it?
I have tried this part of code but it looks like the xsd is not recognized I am getting -1504 error:
v_data_tmp is string
lfileload "path_to_file\file_name.xml", v_data_tmp (I see data loaded to v_data_tmp)
xmlToStruct /validate v_struct, v_data_tmp, "file.xsd" (-1504 error : Unknown element 'PRODUCTIE')
But I do have the element PRODUCTIE defined in the xsd. Where should I store the xsd file if it is only one file and I do not want to use the reference. In the help it is saying that I can place it into working folder. Is that enough? Is it maybe some issue in my xsd file?
<xs:element name="PRODUCTIE">
<xs:complexType>
<xs:sequence>
<xs:element name="PAKKETCODE" type="PakketCode"/>
<xs:element name="KLANTNUMMER" type="KlantNummer"/>
------------------------------
Jozef Prokopovic
Uniface Community Edition Shared Account
US
Original Message:
Sent: 09-20-2024 05:59
From: Ingo Stiller
Subject: XML read and validation with xmltostruct
Hi Jozef
What about UXMLREADER,UXMLWRITER from UnifAce?
About XmlToStruct:
xmlToStruct/full/validate/schema vy_STRUCT, vx_XML,v_UF_SCHEMA_LST
Where
vy_STRUCT is the to be created structure
vx_XML the XML which should be convertet
v_UF_SCHEMA_LST is a schema list as an uniface item list
Ingo
------------------------------
Ingo Stiller
Aareon Deutschland GmbH
Original Message:
Sent: 09-20-2024 03:15
From: Jozef Prokopovic
Subject: XML read and validation with xmltostruct
Hi,
in our application I need to implement reading xml from the folder and then I need to check if the xml is correct. I found the xmlToStruct command. Do you have any example how to use it? First of all what is the best way to read xml and then how the xmltostruct should be used with the xsd schema which is local file in my folder.
My xml files will be some where between 1MB to 30MB.
Are there any other better (more efficient) ways how to do it?
Is it possible to use 3rd party libraries (C, C++, C#, Java) for this goal? If so do you have experience which one is ok and how it can be used in Uniface?
<xs:element name="PRODUCTIE">
<xs:complexType>
<xs:sequence>
<xs:element name="PAKKETCODE" type="PakketCode"/>
<xs:element name="KLANTNUMMER" type="KlantNummer"/>
......etc
BR,
Jozef
------------------------------
Jozef Prokopovic
Uniface Community Edition Shared Account
US
------------------------------