Question
· Mar 17, 2023

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
Discussion (7)2
Log in or sign up to continue

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:

Class dc2303.Field Extends (%Persistent, %XML.Adaptor)
{

Parameter XMLTYPE = "UDFLookupFieldInstance";

Parameter XMLFORMAT = "literal";

Parameter XMLNAME = "Field";

Parameter NAMESPACE = "http://www.civica.co.uk/ParisConnect/ConnectXml/1.0/Messaging";

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 dc2303.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");

/// d ##class(dc2303.Fields).TestFieldsCorrelate()
ClassMethod TestFieldsCorrelate()
{
    Set reader = ##class(%XML.Reader).%New()
    Set tSc=reader.OpenFile("c:\temp\Fields.xml")
    #dim match as Fields
    Do reader.Correlate("Fields","dc2303.Fields")           
    While reader.Next(.match,.tSc) {
        w !, "Hurrah"
    }
    If $$$ISERR(tSc) {
        w !,  $SYSTEM.Status.GetErrorText(tSc)
    }
}

}

And fields.xml is

<Fields xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
    <Field xsi:type="UDFLookupFieldInstance" ID="2925" Description="FIRE ALARM ACTIVE" Suffix="FDT_ACTIVATE"/>
</Fields>