views:

56

answers:

1

I've uploaded a ZIP file containing both the XML file I'm trying to read and the corresponding XSD files to http://www.bonnland.de/FIBEX.zip

I'm trying to deserialize the following XML (fragment) using XmlSerializer. While doing so I get the error: (Sorry for it being German I'll give a rough translation in italics)

System.InvalidOperationException==>Fehler im XML-Dokument (90,7).
System.InvalidOperationException==>Der angegebene Typ wurde nicht erkannt:  Name='CONTROLLER-TYPE', Namespace='http://www.asam.net/xml/fbx/can', bei .

This translates as something like:

System.InvalidOperationException==>error in XML document (90,7).
System.InvalidOperationException==>the given type could not be found: Name='CONTROLLER-TYPE', Namespace='http://www.asam.net/xml/fbx/can', at 

Here's the source document:

<fx:ECU ID="ecuSpeedControl">
  <ho:SHORT-NAME>SpeedControl</ho:SHORT-NAME> 
  <ho:DESC>ECU controlling drive speed</ho:DESC> 
  <fx:CONTROLLERS>
  <fx:CONTROLLER xsi:type="can:CONTROLLER-TYPE" ID="ctrlSpeedControl">
  <ho:SHORT-NAME>ctrlSpeedControl</ho:SHORT-NAME> 
  <ho:DESC>CAN controller of ECU</ho:DESC> 
  <fx:CHIP-NAME>SJA1000</fx:CHIP-NAME> 
  <can:TIME-SEG0>11</can:TIME-SEG0> 
  <can:TIME-SEG1>4</can:TIME-SEG1> 
  <can:SYNC-JUMP-WIDTH>2</can:SYNC-JUMP-WIDTH> 
  <can:NUMBER-OF-SAMPLES>1</can:NUMBER-OF-SAMPLES> 
  </fx:CONTROLLER>
  </fx:CONTROLLERS>
  </fx:ECU>

The root element is:

<fx:FIBEX xmlns:fx="http://www.asam.net/xml/fbx" xmlns:ho="http://www.asam.net/xml"     
    xmlns:can="http://www.asam.net/xml/fbx/can" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="fibex4can.xsd" VERSION="3.1.0">

the class definition for this fragment is:

public ref class FIBEXECU : AbstractFIBEXNode, IGenericContainable
 {
 public:

  ref class ControllersContainer : FIBEXGenericContainer<FIBEXController^>{
  public:
   [XmlElement("CONTROLLER")]
   property array<FIBEXController^>^ ControllerObjs {
    array<FIBEXController^>^ get() { return Children;}
    void set(array<FIBEXController^>^ value) { Children = value;}
   }
  };

  [XmlAttribute("ID")]
  virtual property String^ ID;

  [XmlElement("SHORT-NAME", Namespace="http://www.asam.net/xml")]
  property String^ ShortName;

  [XmlElement("CONTROLLERS")]
  property ControllersContainer^ Controllers;
};

I hope that (yet again) someone can help me, as I didn't find a solution on google or here.

+1  A: 

The error you get seems to indicate that a certain type is not available. Looking through your XSD, there are quite some types undefined, but that's likely because you haven't included the imported and included XSD files, so I cannot reliably check the validity of your documents.

The XML itself contains errors. For instance, the xsi:schemaLocation is not correct, it must contain pairs with the namespace and the location. Instead of this:

xsi:schemaLocation="fibex4can.xsd" 

it should be this (assuming the file is indeed in the same directory as the XML):

xsi:schemaLocation="http://www.asam.net/xml/fbx/can fibex4can.xsd" 

My guess is, that the apparent errors of your document are the reasons that it cannot be parsed. Basically, when dealing with XML, you must be very strict (as with any programming language). If you tell the processor to validate the document, then the Schema's must be available, they must themselves be valid, any related schema's must be locatable and finally, the XML document must be valid against these schema's. Conforming processors (like the ones with .NET) must obey these and other rules for XML and they must throw an error and stop parsing the document when the XML is not well-formed or not valid.

Abel
due to your mentioning of me taking the wrong approach I refactored my application and am now on track again. Thanks again abel
yas4891
@yas4891: you're welcome! Good to see you've taken up an other approach and that you're back "in charge" :)
Abel
yeah. That was really a big help. And sorry for bugging you with this via mail.
yas4891