M
Mark
Hello,
What I am trying todo is use .NET serialization to take a Guid property that is an attribute in the XML document and have its output to be the same as Guid.NewGuid().ToString().ToUpper().Replace("-","")
I have a working copy of this type of class that will work generating an element with the output i have and the following is an example of that code. What i run into is making the element an attribute then it breaks and does not work. What can i do to make this work?
[System.Xml.Serialization.XmlTypeAttribute(Namespace="XML.Fun")]
[System.Xml.Serialization.XmlRootAttribute(Namespace="XML.Fun", IsNullable=false)]
public class DataObject
{
//[System.Xml.Serialization.XmlAttributeAttribute()]
public GuidId gId;
public DataObject()
{
gId = new GuidId();
gId.TheGuidId = Guid.NewGuid();
}
}
public class GuidId : IXmlSerializable
{
public Guid TheGuidId;
public System.Xml.Schema.XmlSchema GetSchema ( )
{
return null;
}
public void ReadXml ( System.Xml.XmlReader reader )
{
}
public void WriteXml ( System.Xml.XmlWriter writer )
{
writer.WriteString( TheGuidId.ToString().ToUpper().Replace("-","") );
}
}
The XML output
<?xml version="1.0" encoding="utf-16"?>
<DataObject xmlns="XML.Fun">
<gId>A5E13ADD55B7429D8E84816D5B6FCDF5</gId>
</DataObject>
The XML output that i would like to have is
<?xml version="1.0" encoding="utf-16"?>
<DataObject xmlns="XML.Fun" gId="A5E13ADD55B7429D8E84816D5B6FCDF5">
</DataObject>
Thank you for any help.
What I am trying todo is use .NET serialization to take a Guid property that is an attribute in the XML document and have its output to be the same as Guid.NewGuid().ToString().ToUpper().Replace("-","")
I have a working copy of this type of class that will work generating an element with the output i have and the following is an example of that code. What i run into is making the element an attribute then it breaks and does not work. What can i do to make this work?
[System.Xml.Serialization.XmlTypeAttribute(Namespace="XML.Fun")]
[System.Xml.Serialization.XmlRootAttribute(Namespace="XML.Fun", IsNullable=false)]
public class DataObject
{
//[System.Xml.Serialization.XmlAttributeAttribute()]
public GuidId gId;
public DataObject()
{
gId = new GuidId();
gId.TheGuidId = Guid.NewGuid();
}
}
public class GuidId : IXmlSerializable
{
public Guid TheGuidId;
public System.Xml.Schema.XmlSchema GetSchema ( )
{
return null;
}
public void ReadXml ( System.Xml.XmlReader reader )
{
}
public void WriteXml ( System.Xml.XmlWriter writer )
{
writer.WriteString( TheGuidId.ToString().ToUpper().Replace("-","") );
}
}
The XML output
<?xml version="1.0" encoding="utf-16"?>
<DataObject xmlns="XML.Fun">
<gId>A5E13ADD55B7429D8E84816D5B6FCDF5</gId>
</DataObject>
The XML output that i would like to have is
<?xml version="1.0" encoding="utf-16"?>
<DataObject xmlns="XML.Fun" gId="A5E13ADD55B7429D8E84816D5B6FCDF5">
</DataObject>
Thank you for any help.