SBX - Search With Button

SBX - Forum Post Title

I try to send an XML, but it shows the following error, how can I identify it?

Microsoft Dynamics AX Forum

ismaelivan asked a question on 12 Oct 2018 5:45 PM
My Badges

Question Status

Unanswered

How i can identify the next error:

Failed to validate the identity restriction 'tempuri.org/DSCargaRemisionProv.xsd:DSCargaRemisionProvKey3'. A key is missing or the existing key has an empty node.

The XSD is:

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="DSCargaRemisionProv" targetNamespace="http://tempuri.org/DSCargaRemisionProv.xsd"
	elementFormDefault="qualified" attributeFormDefault="qualified" xmlns="http://tempuri.org/DSCargaRemisionProv.xsd"
	xmlns:mstns="http://tempuri.org/DSCargaRemisionProv.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema"
	xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
	<xs:element name="DSCargaRemisionProv" msdata:IsDataSet="true">
		<xs:complexType>
			<xs:choice maxOccurs="unbounded">
				<xs:element name="Remision">
					<xs:complexType>
						<xs:sequence>
							<xs:element name="Proveedor" type="xs:int" />
							<xs:element name="Remision" type="xs:string" />
							<xs:element name="Consecutivo" type="xs:short" />
							<xs:element name="FechaRemision" type="xs:dateTime" />
							<xs:element name="Tienda" type="xs:short" />
							<xs:element name="TipoMoneda" type="xs:short" />
							<xs:element name="TipoBulto" type="xs:short" />
							<xs:element name="EntregaMercancia" type="xs:short" />
							<xs:element name="CumpleReqFiscales" type="xs:boolean" />
							<xs:element name="CantidadBultos" type="xs:decimal" />
							<xs:element name="Subtotal" type="xs:decimal" />
							<xs:element name="IEPS" type="xs:decimal" />
							<xs:element name="IVA" type="xs:decimal" />
							<xs:element name="OtrosImpuestos" type="xs:decimal" />
							<xs:element name="Total" type="xs:decimal" />
							<xs:element name="CantidadPedidos" type="xs:int" />
							<xs:element name="FechaEntregaMercancia" type="xs:dateTime" />
							<xs:element name="Cita" type="xs:int" minOccurs="0" />
						</xs:sequence>
					</xs:complexType>
				</xs:element>
				<xs:element name="Pedimento">
					<xs:complexType>
						<xs:sequence>
							<xs:element name="Proveedor" type="xs:int" />
							<xs:element name="Remision" type="xs:string" />
							<xs:element name="Pedimento" type="xs:int" />
							<xs:element name="Aduana" type="xs:short" />
							<xs:element name="AgenteAduanal" type="xs:short" />
							<xs:element name="TipoPedimento" type="xs:string" />
							<xs:element name="FechaPedimento" type="xs:dateTime" />
							<xs:element name="FechaReciboLaredo" type="xs:dateTime" />
							<xs:element name="FechaBillOfLading" type="xs:dateTime" />
						</xs:sequence>
					</xs:complexType>
				</xs:element>
				<xs:element name="Pedidos">
					<xs:complexType>
						<xs:sequence>
							<xs:element name="Proveedor" type="xs:int" />
							<xs:element name="Remision" type="xs:string" />
							<xs:element name="FolioPedido" type="xs:int" />
							<xs:element name="Tienda" type="xs:short" />
							<xs:element name="CantidadArticulos" type="xs:int" />
						</xs:sequence>
					</xs:complexType>
				</xs:element>
				<xs:element name="Articulos">
					<xs:complexType>
						<xs:sequence>
							<xs:element name="Proveedor" type="xs:int" />
							<xs:element name="Remision" type="xs:string" />
							<xs:element name="FolioPedido" type="xs:int" />
							<xs:element name="Tienda" type="xs:short" />
							<xs:element name="Codigo" type="xs:decimal" />
							<xs:element name="CantidadUnidadCompra" type="xs:decimal" />
							<xs:element name="CostoNetoUnidadCompra" type="xs:decimal" />
							<xs:element name="PorcentajeIEPS" type="xs:decimal" />
							<xs:element name="PorcentajeIVA" type="xs:decimal" />
						</xs:sequence>
					</xs:complexType>
				</xs:element>
			</xs:choice>
		</xs:complexType>
		<xs:key name="DSCargaRemisionProvKey1" msdata:PrimaryKey="true">
			<xs:selector xpath=".//Remision" />
			<xs:field xpath="mstns:Proveedor" />
			<xs:field xpath="Remision" />
		</xs:key>
		<xs:key name="DSCargaRemisionProvKey3" msdata:PrimaryKey="true">
			<xs:selector xpath=".//mstns:Pedimento" />
			<xs:field xpath="mstns:Proveedor" />
			<xs:field xpath="Remision" />
		</xs:key>
		<xs:key name="DSCargaRemisionProvKey4" msdata:PrimaryKey="true">
			<xs:selector xpath=".//mstns:Pedidos" />
			<xs:field xpath="mstns:Proveedor" />
			<xs:field xpath="Remision" />
			<xs:field xpath="mstns:FolioPedido" />
		</xs:key>
		<xs:key name="DSCargaRemisionProvKey5" msdata:PrimaryKey="true">
			<xs:selector xpath=".//Articulos" />
			<xs:field xpath="mstns:Proveedor" />
			<xs:field xpath="mstns:Remision" />
			<xs:field xpath="mstns:FolioPedido" />
			<xs:field xpath="mstns:Tienda" />
			<xs:field xpath="mstns:Codigo" />
		</xs:key>
		<xs:keyref name="RemisionPedimento" refer="DSCargaRemisionProvKey1">
			<xs:selector xpath=".//mstns:Pedimento" />
			<xs:field xpath="mstns:Proveedor" />
			<xs:field xpath="Remision" />
		</xs:keyref>
		<xs:keyref name="RemisionPedidos" refer="DSCargaRemisionProvKey1">
			<xs:selector xpath=".//mstns:Pedidos" />
			<xs:field xpath="mstns:Proveedor" />
			<xs:field xpath="Remision" />
		</xs:keyref>
		<xs:keyref name="PedidosArticulos" refer="DSCargaRemisionProvKey4">
			<xs:selector xpath=".//mstns:Articulos" />
			<xs:field xpath="mstns:Proveedor" />
			<xs:field xpath="Remision" />
			<xs:field xpath="mstns:FolioPedido" />
		</xs:keyref>
		<xs:key name="DSCargaRemisionProvKey6" msdata:PrimaryKey="true">
			<xs:selector xpath=".//mstns:Articulos" />
			<xs:field xpath="mstns:Proveedor" />
			<xs:field xpath="Remision" />
			<xs:field xpath="mstns:FolioPedido" />
			<xs:field xpath="mstns:Tienda" />
			<xs:field xpath="mstns:Codigo" />
		</xs:key>
	</xs:element>
</xs:schema>


Thanks in advance!!

Reply
Martin Dráb responded on 13 Oct 2018 1:15 AM

Please tell us what you're doing and when you got the error.

Reply
ismaelivan responded on 15 Oct 2018 11:15 AM
My Badges

It shows me the error when I compare the xsd with the following xml (XmlTextReader.validate)

<DSCargaRemisionProv xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/DSCargaRemisionProv.xsd" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" schemaLocation="http://tempuri.org/DSCargaRemisionProv.xsd schema.xsd"><Remision><Proveedor>123456</Proveedor><Remision>B00080866</Remision><Consecutivo>1234</Consecutivo><FechaRemision>2018-04-20T14:56:22</FechaRemision><Tienda>5519</Tienda><TipoMoneda>1</TipoMoneda><TipoBulto>1</TipoBulto><EntregaMercancia>1</EntregaMercancia><CumpleReqFiscales>true</CumpleReqFiscales><CantidadBultos>52.0000</CantidadBultos><Subtotal>47840.0000</Subtotal><IEPS>0.0000</IEPS><IVA>7654.4000</IVA><OtrosImpuestos>0.0000</OtrosImpuestos><Total>55494.4000</Total><CantidadPedidos>1</CantidadPedidos><FechaEntregaMercancia>2018-04-19T19:00:00</FechaEntregaMercancia><Cita>0</Cita><FolioNotaEntrada /></Remision><Pedimento><Proveedor>123456</Proveedor><Remision>B00080866</Remision><Pedimento>0</Pedimento><Aduana>1234</Aduana><AgenteAduanal>1234</AgenteAduanal><TipoPedimento>string</TipoPedimento><FechaPedimento>2018-09-10T14:47:04</FechaPedimento><FechaReciboLaredo>2018-09-10T14:47:04</FechaReciboLaredo><FechaBillOfLading>2018-09-10T14:47:04</FechaBillOfLading></Pedimento><Pedidos><Proveedor>303030</Proveedor><Remision>B00080866</Remision><FolioPedido>324233</FolioPedido><Tienda>5519</Tienda><CantidadArticulos>1</CantidadArticulos></Pedidos><Articulos><Proveedor>303030</Proveedor><Remision>B00080866</Remision><FolioPedido>324233</FolioPedido><Tienda>5519</Tienda><Codigo>0.0</Codigo><CantidadUnidadCompra>52.0000</CantidadUnidadCompra><CostoNetoUnidadCompra>47840.0000</CostoNetoUnidadCompra><PorcentajeIEPS>0.0</PorcentajeIEPS><PorcentajeIVA>16.0000</PorcentajeIVA></Articulos></DSCargaRemisionProv>


Thanks Martín

Reply
Martin Dráb responded on 15 Oct 2018 11:55 AM

All right, I put both files to Visual Studio (which can validate XML files against schemas) and it indeed found several schema violations.

I think your XPath expressions aren't correct. Regarding DSCargaRemisionProvKey3, wouldn't this simpler definition work better?

<xs:key name="DSCargaRemisionProvKey3" msdata:PrimaryKey="true">
  <xs:selector xpath="Pedimento" />
  <xs:field xpath="Proveedor" />
  <xs:field xpath="Remision" />
</xs:key>
Reply
ismaelivan responded on 16 Oct 2018 11:31 AM
My Badges

Unfortunately I can not modify it, I must adapt my xml with that structure.  But that error does not tell me much

Reply
Martin Dráb responded on 17 Oct 2018 5:42 AM

Unless somebody explain to my where there is the same namespace at the default one and as mstns, I think it's a bug. That they randomly use the default namespace and mstns just complicates everything without adding any value.

Using DSCargaRemisionProvKey3 as an example, I have no idea why there are two namespaces.

<xs:key name="DSCargaRemisionProvKey3" msdata:PrimaryKey="true">
  <xs:selector xpath=".//mstns:Pedimento" />
  <xs:field xpath="mstns:Proveedor" />
  <xs:field xpath="Remision" />
</xs:key>

I would expect all with the default namespace (as I've shown above) or all with the mstns prefix.

If you really can't get the schema fixed, consider whether you really want to work with the owner.

You can add mstns: to Pedimento, which will pass the check for .//mstns:Pedimento and mstns:Proveedor. But it'll fail on Remision (which doesn't have mstns prefix in the schema) and I don't know how you can switch to the default schema).

Consider asking in a forum about XML instead of about Dynamics AX. Maybe an XML specialist will give you a better answer.

Reply

SBX - Two Col Forum

SBX - Migrated JS