Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All

I generated an XML from a Simulink (Matlab 2017b) model. The idea is to get the Model Properties from the XML into Class Objects (I am using C# .Net 4.5). Below in the generated XML.

<?xml version="1.0" encoding="utf-8"?>
<ModelInformation Version="1.0">
  <Model Name="MatlabToJenkinsIntegrationSample">
    <P Name="Version">9.0</P>
    <P Name="SavedCharacterEncoding">windows-1252</P>
    <GraphicalInterface>
      <P Name="NumRootInports">3</P>
      <Inport Name="Input1">
        <P Name="BusObject"/>
        <P Name="OutputFunctionCall">off</P>
        <P Name="SampleTime">-1</P>
        <P Name="UnitExpr">inherit</P>
      </Inport>
      <Inport Name="Input2 ">
        <P Name="BusObject"/>
        <P Name="OutputFunctionCall">off</P>
        <P Name="SampleTime">-1</P>
        <P Name="UnitExpr">inherit</P>
      </Inport>
      <Inport Name="MultiplicationFactor">
        <P Name="BusObject"/>
        <P Name="OutputFunctionCall">off</P>
        <P Name="SampleTime">-1</P>
        <P Name="UnitExpr">inherit</P>
      </Inport>
      <P Name="NumRootOutports">1</P>
      <Outport Name="Result">
        <P Name="BusObject"/>
        <P Name="BusOutputAsStruct">off</P>
        <P Name="UnitExpr">inherit</P>
      </Outport>
      <P Name="ParameterArgumentNames"/>
      <P Name="ComputedModelVersion">1.4</P>
      <P Name="NumModelReferences">0</P>
      <P Name="NumTestPointedSignals">0</P>
      <P Name="NumProvidedFunctions">0</P>
      <P Name="NumRequiredFunctions">0</P>
      <P Name="NumResetEvents">0</P>
      <P Name="HasInitializeEvent">0</P>
      <P Name="HasTerminateEvent">0</P>
      <P Name="IsExportFunctionModel">0</P>
      <P Name="NumParameterArguments">0</P>
      <P Name="NumExternalFileReferences">0</P>
      <P Name="OrderedModelArguments">1</P>
    </GraphicalInterface>
  </Model>
</ModelInformation>


The issue I am having is that it does not look like any traditional XML I have seen.

Still the questions remain I do I read them into the objects. I looked at a solution ([Solution]) but it was not suitable for this kind of XML. Please suggest a way.

What I have tried:

I created classes to get the objects as shown below

<pre>public class Model
{
        
    public string Name { get; set; }
      
    public string Version { get; set; }
        
    public string SavedCharacterEncoding { get; set; }
       
    public GraphicalInterface TheGraphicalInterface { get; set; }
}


public class GraphicalInterface
{
    public List<Port> InPorts { get; set; }

    public List<Port> OutPorts { get; set; }
}


public class Port
{
       
    public string OutputFunctionCall { get; set; }
      
    public double SampleTime { get; set; }
   
    public string UnitExpression { get; set; }
}
Posted
Updated 4-Feb-18 11:07am
Comments
Tomas Takac 16-Jan-18 6:46am    
You are right, this doesn't look very traditionally. Can you tweak how the XML is generated? Maybe there is a parameter which drives this.
KumarAbhishekJaiswal 16-Jan-18 6:55am    
@tomas I wish I could. I have contacted Mathworks for this. Waiting for their response. I have no idea now what to do.
Kornfeld Eliyahu Peter 16-Jan-18 9:19am    
I would say you should transform it to a more 'traditional' XML using XSLT...
As much as I can see all you have to change is all those <P> elements (representing properties?)
from:
<P Name="HasTerminateEvent">0</P>
to:
<HasTerminateEvent value="0"/>
Tomas Takac 16-Jan-18 10:02am    
Good idea. I guess he also needs to wrap the collections as <inports><inport/><inport/>....</inports>
KumarAbhishekJaiswal 16-Jan-18 10:52am    
but is there a tool to do so? because I am not aware of it. Please suggest

1 solution

it does not look like any traditional XML


You're wrong. This xml has proper form. See: XML attributes[^].

I did exactly what is described here: c# - How to Deserialize XML document - Stack Overflow[^] and the classes generated by xsd.exe tool are totally different then yours. Follow these steps and generate proper classes to be able to use xml serialization/deserialization.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900