XML.Reader correlate produces ERROR #6277: Type attribute does not specify valid type for XML input tag
I'm using %XML.Reader to open an XML file and use it's correlate method to try and convert it to a class.
The conversion fails with an error of:
ERROR #6277: Type attribute, LimitedFreeTextFieldInstance, does not specify valid type for XML input tag: Field (ending at line 3 character 118).
This is the XML
<Fields xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<Field xsi:type="UDFLookupFieldInstance" ID="2925" Description="FIRE ALARM ACTIVE" Suffix="FDT_ACTIVATE"/>
</Fields>
This error is produced when xsi:type is any value, when it is left blank conversion using the code listed below is successful.
The XML I'm working with is produced by a third party and can't changed.
I can't figure out why. Can anyone help?
The classes are as follows:
Class Field Extends (%Persistent, %XML.Adaptor)
{
Parameter XMLFORMAT = "literal";
Parameter XMLNAME = "Field";
Parameter NAMESPACE = "http://www.civica.co.uk/ParisConnect/ConnectXml/1.0/Messaging";
Property Type As %String(XMLNAME = "xsi:type", XMLPROJECTION = "ATTRIBUTE");
Property Suffix As %String(XMLNAME = "Suffix", XMLPROJECTION = "ATTRIBUTE");
Property Description As %String(XMLNAME = "Description", XMLPROJECTION = "ATTRIBUTE");
Property ID As %String(XMLNAME = "ID", XMLPROJECTION = "ATTRIBUTE");
}
Class Fields Extends (%Persistent, %XML.Adaptor)
{
Parameter XMLFORMAT = "literal";
Parameter XMLNAME = "Fields";
Parameter XMLSEQUENCE = 1;
Parameter NAMESPACE = "http://www.civica.co.uk/ParisConnect/ConnectXml/1.0/Messaging";
Parameter SUPPRESSTYPEPREFIX = 1;
Property Fields As list Of Field(XMLNAME = "Field", XMLPROJECTION = "ELEMENT");
}
And I test with
ClassMethod TestFieldsCorrelate()
{
Set reader = ##class(%XML.Reader).%New()
Set tSc=reader.OpenFile("E:\temp\Fields.xml")
#dim match as Fields
Do reader.Correlate("Fields","Fields")
While reader.Next(.match,.tSc) {
w !, "Hurrah"
}
If $$$ISERR(tSc) {
w !, $SYSTEM.Status.GetErrorText(tSc)
}
}
Any feedback, thoughts, comments would be greatfuly received.
Cheers
Andy
Product version: IRIS 2021.1
$ZV: IRIS for Windows (x86-64) 2021.2.1 (Build 654U) Fri Mar 18 2022 06:09:35 EDT
xsi:type is a special attribute
IRIS analogue is XMLTYPE parameter of the class,
You need to remove Property Type from the Field class and add the following parameter, then recompile both Field and Fields
Hi Alexander
Thanks for the reply, but your suggestion didn't work.
Andy
Should work. I actually tested it. Did you recompile both classes? Do you get the same error still?
Yes I did, I change the class Field to the following and compiled? Is this correct?
Class Field Extends (%Persistent, %XML.Adaptor) { Parameter XMLNAME = "Field"; Parameter NAMESPACE = "http://www.civica.co.uk/ParisConnect/ConnectXml/1.0/Messaging"; // Property Type As %String(XMLNAME = "xsi:type", XMLPROJECTION = "ATTRIBUTE"); Parameter XMLTYPE = "UDFLookupFieldInstance"; Property Suffix As %String(XMLNAME = "Suffix", XMLPROJECTION = "ATTRIBUTE"); Property Description As %String(XMLNAME = "Description", XMLPROJECTION = "ATTRIBUTE"); Property ID As %String(XMLNAME = "ID", XMLPROJECTION = "ATTRIBUTE"); Property Value As %String(MAXLEN = "", XMLNAME = "Value"); }
The same error is produced.
In my original post I did mention that that xsi:value can be anything, so assuming I made a mistake what would I need to do to this into account?
Recompile also FIelds class.
Yes, looks correct.
I have the following classes:
And fields.xml is
It turns out there was a whitespace in my code which I hadn't noticed, so that code works. Thanks for taking the time to reply.
So, that solves one problem. The source data can have many different values for xsi:type, so how to take that into account@?
The best option -- create XSD from the XML or get XSD from the XML provider, import the XSD in IRIS, that will generate set of classes to import XML to
Other way -- manually create classes for each different xsi:type
Social networks
InterSystems resources
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue