Re: xsd to xml robot task
Do you have a sample of the xml?
1 Attachment(s)
Re: xsd to xml robot task
This is a file exported from the simulation program. There is just a few Activity elements in the ActivityList which describes the robot movements.
In reality the xml files to be created would maybe have more than 100.
Thanks for taking an interest in this, I really appreciate it.
Re: xsd to xml robot task
The approach I would take is to use Xml Serialization. Check out my response in this thread: http://www.codeguru.com/forum/showthread.php?t=507807
Take a portion of the xml file and try to serialize it.
See if you can do it. Post back if you run into trouble.
Re: xsd to xml robot task
I ran into trouble ;)
Is there a clever way to handle "nested" elements?
ResourceType is located inside OLPData, but how do I get both of them out in the same xml structure?
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;
class Program
{
static void Main(string[] args)
{
XmlSerializer serializer = new XmlSerializer(typeof(OLPData));
TextWriter writer = new StreamWriter("Delmia file.xml");
OLPData olpData = new OLPData();
olpData.Context = "Some context";
olpData.DownloaderRootDirectory = "Some download directory";
olpData.LogFileName = "Some filename";
ResourceType resourceType = new ResourceType();
resourceType.id = "Some id";
serializer.Serialize(Console.Out, olpData);
Console.Read();
}
}
Re: xsd to xml robot task
What do your classes and xml related attributes look like?
1 Attachment(s)
Re: xsd to xml robot task
The complete class file is attached (generated from xsd.exe), but here are the first two classes referred to in my last post.
Code:
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.1
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System.Xml.Serialization;
//
// This source code was auto-generated by xsd, Version=4.0.30319.1.
//
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
public partial class OLPData {
private ResourceType resourceField;
private string contextField;
private string logFileNameField;
private string downloaderRootDirectoryField;
/// <remarks/>
public ResourceType Resource {
get {
return this.resourceField;
}
set {
this.resourceField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string Context {
get {
return this.contextField;
}
set {
this.contextField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string LogFileName {
get {
return this.logFileNameField;
}
set {
this.logFileNameField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string DownloaderRootDirectory {
get {
return this.downloaderRootDirectoryField;
}
set {
this.downloaderRootDirectoryField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class ResourceType {
private GeneralInfoType generalInfoField;
private ControllerType controllerField;
private ParameterListType parameterListField;
private DeviceType[] mountedDevicesField;
private ActivityListType[] activityListField;
private string idField;
private string resourceType1Field;
private string logicXMLFileLocationField;
/// <remarks/>
public GeneralInfoType GeneralInfo {
get {
return this.generalInfoField;
}
set {
this.generalInfoField = value;
}
}
/// <remarks/>
public ControllerType Controller {
get {
return this.controllerField;
}
set {
this.controllerField = value;
}
}
/// <remarks/>
public ParameterListType ParameterList {
get {
return this.parameterListField;
}
set {
this.parameterListField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("Device", IsNullable=false)]
public DeviceType[] MountedDevices {
get {
return this.mountedDevicesField;
}
set {
this.mountedDevicesField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("ActivityList")]
public ActivityListType[] ActivityList {
get {
return this.activityListField;
}
set {
this.activityListField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute(DataType="NMTOKEN")]
public string id {
get {
return this.idField;
}
set {
this.idField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute("ResourceType", DataType="token")]
public string ResourceType1 {
get {
return this.resourceType1Field;
}
set {
this.resourceType1Field = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute(DataType="token")]
public string LogicXMLFileLocation {
get {
return this.logicXMLFileLocationField;
}
set {
this.logicXMLFileLocationField = value;
}
}
}
Re: xsd to xml robot task
The ResourceType property doesn't have an xml attribute.
Re: xsd to xml robot task
Thanks for the response.
I am not exactly sure about what you mean when you say property.
I thought e.g. id was one of the attributes of ResourceType.
Anyway, does this mean that I would have to edit the class file manually, or is what I am trying to do unfeasible?
Code:
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute(DataType="NMTOKEN")]
public string id {
get {
return this.idField;
}
set {
this.idField = value;
}
}
Re: xsd to xml robot task
You've got a mismatch between the actual xml and the xsd generated code.
Xml
Code:
<OLPData...>
<Resource ResourceType="Robot" id="12455066">
</Resource>
</OLPData>
Generated code expects xml of this type
Code:
<OLPData...>
<ResourceType ResourceType="Robot" id="12455066">
</Resource>
</OLPData>