Bug #10203
XMLs cannot be imported into a dataset without a schema present
100%
Related issues
History
#1 Updated by Dennis-Alexandru Niță about 1 year ago
In 4GL, it is possible to import an XML file into a DATASET handle without a pre-existing schema. The dataset structure is expected to be created dynamically based on the XML content.
PROCEDURE test:
DEF VAR ds1 AS HANDLE NO-UNDO.
CREATE DATASET ds1.
ds1:READ-XML("file", "tmp.xml", "EMPTY", ?, ?).
END.
When executing a similar test in FWD, the XML import fails with the following error, indicating a problem with temp-table preparation:
╷
└─ FWD Test ✔
└─ XmlToJson ✔
└─ xmltoJsontest ✘ TEMP-TABLE object must have at least one field before TEMP-TABLE-PREPARE can be called. (9033)
The possible cause may be at: XmlImport.java:568:
if (isRoot)
{
isRoot = false;
dsName = name;
nsUri = reader.getNamespaceURI();
nsPrefix = reader.getPrefix();
dataSetNameMatch = ds._name().equals(dsName) ||
ds.getSerializeName().getValue().equals(dsName) ||
ds.getXmlNodeName().getValue().equals(dsName);
}
...
Each node within the XML is parsed and the problem may be the root node:
Error 9033 may happen because there isn't a temporary table created for the root node. There's no schema to back this up and also, the logic above doesn't take that into consideration.
Further debugging reveals that even if the initial error is manually bypassed (e.g., by creating a temp-table), the XML parsing is flawed.
- Any attributes present on the root XML element are ignored.
- The hierarchical structure (nesting) of the XML is not correctly interpreted, leading to an incomplete or malformed dataset.
#2 Updated by Dennis-Alexandru Niță about 1 year ago
- Status changed from New to WIP
- Assignee set to Dennis-Alexandru Niță
Created branch 10203a from latest revision 16032.
#3 Updated by Constantin Asofiei about 1 year ago
For this test:
def var ds1 as handle.
create dataset ds1.
ds1:READ-XML("file", "tmp.xml", "EMPTY", ?, ?).
ds1:write-xml("file", "out.xml").
message ds1:name ds1:xml-node-type.
For this XML:
<?xml version="1.0" encoding="UTF-8"?>
<ViewResourceMetadata IsDefaultHybridBrowse="true">
<Test> hello </Test>
</ViewResourceMetadata>
you get
NewDataSet as dataset name, and ds1:xml-node-type is HIDDEN!:<?xml version="1.0"?> <ViewResourceMetadata xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" IsDefaultHybridBrowse="true"> <Test> hello </Test> </ViewResourceMetadata>
For this test:
<foo>
<ViewResourceMetadata xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" IsDefaultHybridBrowse="true">
<Test> hello </Test>
</ViewResourceMetadata>
</foo>
you get
foo as dataset name and this result:
<?xml version="1.0"?>
<foo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ViewResourceMetadata IsDefaultHybridBrowse="true">
<Test> hello </Test>
</ViewResourceMetadata>
</foo>
Conclusion: if the root node has attributes, the the XML has a single-table dataset (as you can't have multiple root nodes).
Please check other DATASET attributes related to XML and serialization.
#4 Updated by Dennis-Alexandru Niță about 1 year ago
For the following code:
DEFINE VARIABLE ds1 AS HANDLE NO-UNDO.
CREATE DATASET ds1.
ds1:READ-XML("file", "in.xml", "EMPTY", ?, ?).
ds1:WRITE-XML ("file", "out.xml").
The following XML:
<?xml version="1.0" encoding="UTF-8"?> <ViewResourceMetadata IsDefaultHybridBrowse="true"> <Test> hello </Test> </ViewResourceMetadata>
fails with the following error message:TEMP-TABLE object must have at least one field before TEMP-TABLE-PREPARE can be called. (9033) in latest trunk revision.
But I've found that the following XML:
<?xml version="1.0" encoding="UTF-8"?> <ViewResourceMetadata IsDefaultHybridBrowse="true"> <Test testatr="test"> hello </Test> </ViewResourceMetadata>
doesn't fail !
The only change is that the Test node has an attribute in the passing test, but doesn't have any in the failing test.
I need to investigate this more as I surely didn't understand the underlying issue myself.
#5 Updated by Dennis-Alexandru Niță about 1 year ago
I've made some tests and looked over the existing code.
The used read-write FWD procedure:
DEFINE VARIABLE ds1 AS HANDLE NO-UNDO.
CREATE DATASET ds1.
ds1:READ-XML("file", "in.xml", "EMPTY", ?, ?).
ds1:WRITE-XML ("file", "out.xml").
message ds1:name ds1:xml-node-type.
- Issue 1:
The following XML undergoes a read-write procedure in FWD:
<?xml version="1.0" encoding="UTF-8"?> <RootTest attr1="test"> <Variable>test</Variable> </RootTest>
Gets converted to:
<?xml version='1.0'?> <RootTest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Variable/> </RootTest>
Both root's attribute and
Variable's text are lost.
Here the dataset's name is RootTest and XML node-type ELEMENT!
The problem is that the XML isn't wrapped in a NewDataSet hidden new root node.
I couldn't find anything about creating a NewDataSet wrapper hidden node.
In Importer.java:706, method setupDataset(String name), the dataset is set to NewDataSet if and only if there isn't another name provided.
But in XmlImport.java:529 a name is always provided - in XmlImport.java:569 the dataset's name is set to the START_ELEMENT's name.
For the following code (I've enforced a NewDataSet root with the same structure as above):
<?xml version="1.0" encoding="UTF-8"?>
<NewDataSet>
<RootTest attr1="test">
<Variable>test</Variable>
</RootTest>
</NewDataSet>
We get:
<?xml version='1.0'?>
<NewDataSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RootTest attr1="test">
<Variable>
test
</Variable>
</RootTest>
</NewDataSet>
We can see that no data is lost now. So we must fix the NewDataSet node that hasn't been added in the previous examples.
- Issue 2:
We can see, even with the NewDataSet node that fixes the TEMP-TABLE object must have at least one field before TEMP-TABLE-PREPARE can be called. (9033) error, we get an incomplete dataset.
<GeologicalSurvey SurveyId="urn:survey:program:corp.xyz.KEPLER_186F:geo"/> <SurfaceTemperature>ANOTHER RANDOM VALUE IN A DIFFERENT PLACE</SurfaceTemperature>
These two nodes are lost because persisted = true at XmlImport.java:3343.
if( --nest == -1)
{
return persisted ? true : persist(maker, readValues, parent != null);
}
It shouldn't be
true at this moment.
I'll be investigating more in-depth these issues.
#6 Updated by Teodor Gorghe about 1 year ago
- Related to Bug #10308: DYNAMIC TEMP-TABLE issue when using READ-XML before TEMP-TABLE-PREPARE added
#8 Updated by Constantin Asofiei 10 months ago
- Status changed from WIP to New
- Assignee changed from Dennis-Alexandru Niță to Eduard Soltan
#9 Updated by Teodor Gorghe 9 months ago
- Assignee changed from Eduard Soltan to Teodor Gorghe
Rebased branch 10203a to trunk revision 16219.
#10 Updated by Teodor Gorghe 9 months ago
- Related to Bug #10351: ProDataSet READ-XML issue when temp-table node is the same as dataset node added
#11 Updated by Teodor Gorghe 9 months ago
- Status changed from New to WIP
- % Done changed from 0 to 50
Committed revision 106220 on task branch 10203a:
- Improved DATASET:READ-XML infer support when DATASET node is hidden.
Even that this fixes the reported issue, the remaining issues is:
- No support for TEXT fields, according to the XmlImport:3377.
- When there is a child node, without any element childs but with field attributes, these attributes are not parsed. It is considered as a field value. It is a very similar issue with #10560 (I think I should pull the changes).
#12 Updated by Constantin Asofiei 6 months ago
Teodor, what else is needed here?
#13 Updated by Teodor Gorghe 6 months ago
Yes, there is still more work to do, but it is not related with an issue reported by a customer.
I have worked for a fix on this, there are lot of changes of READ-XML when inferring the dataset, but I think I shall commit the changes as it is (some of it is a workaround).
#14 Updated by Teodor Gorghe 6 months ago
- File 10203_tests.zip added
- Status changed from WIP to Review
- % Done changed from 50 to 100
- reviewer Constantin Asofiei added
Committed revision 16221 on task branch 10203a:
- Added implementation for TEXT field when infering READ-XML structure.
Constantin, please review my changes. I might have missed to put JavaDoc somewhere. Please note that these changes were made long ago, when I have worked on this branch, but never committed because of the need for change on XmlImport:699.
#15 Updated by Teodor Gorghe 6 months ago
Rebased to trunk rev 16358
#16 Updated by Constantin Asofiei 6 months ago
10203a rev 16361 fixes copyright years. Otherwise, changes are OK. This was already tested via #10615.
#17 Updated by Constantin Asofiei 6 months ago
Merge to trunk after 11048a
#18 Updated by Teodor Gorghe 6 months ago
- Status changed from Review to Test
Branch 10203a was merged to trunk rev. 16391 and archived.
#19 Updated by Constantin Asofiei 6 months ago
- Status changed from Test to Closed