私はこれらの2つのクラスを持っています
[XmlRoot(ElementName="XMI", Namespace = XmiStrings.XmiNamespace)]
public class XMIElement
{
[XmlAttribute("version", Namespace = XmiStrings.XmiNamespace)]
public string Version { get; set; }
[XmlAttribute("schemaLocation", Namespace = XmiStrings.XsiNamespace)]
public string SchemaLocation { get; set; }
}
public static class XmiStrings
{
public const string XmiNamespace = "http://schema.omg.org/spec/XMI/2.1";
public const string XsiNamespace = "http://www.w3.org/2001/XMLSchema-instance";
public const string PackageTypesNamespace = "http://SysID_Profile.ServiceProfile/schemas/PackageTypes/_zdnHsHCBEeKdD9Oad6OUOQ/0";
public const string RHPNamespace = "http://RhapsodyStandardModel.RhpProperties/schemas/RHP/_zddWsXCBEeKdD9Oad6OUOQ/0";
public const string RhapsodyProfileNamespace = "http://RhapsodyStandardModel/schemas/RhapsodyProfile/_zddWsHCBEeKdD9Oad6OUOQ/0";
public const string ServiceProfileNamespace = "http://SysID_Profile/schemas/ServiceProfile/_zdnHsXCBEeKdD9Oad6OUOQ/0";
public const string SimpleTypesNamespace = "http://SysID_Profile.ServiceProfile/schemas/SimpleTypes/_zddWsnCBEeKdD9Oad6OUOQ/0";
public const string StandardNamespace = "http://schema.omg.org/spec/UML/2.1/StandardProfileL2";
public const string EcoreNamespace = "http://www.eclipse.org/emf/2002/Ecore";
public const string UmlNamespace = "http://schema.omg.org/spec/UML/2.1";
public const string SchemaLocation = "http://SysID_Profile.ServiceProfile/schemas/PackageTypes/_zdnHsHCBEeKdD9Oad6OUOQ/0 #_zpg3YHCBEeKdD9Oad6OUOQ http://RhapsodyStandardModel.RhpProperties/schemas/RHP/_zddWsXCBEeKdD9Oad6OUOQ/0 #_zpqBA3CBEeKdD9Oad6OUOQ http://RhapsodyStandardModel/schemas/RhapsodyProfile/_zddWsHCBEeKdD9Oad6OUOQ/0 #_zpp_o3CBEeKdD9Oad6OUOQ http://SysID_Profile/schemas/ServiceProfile/_zdnHsXCBEeKdD9Oad6OUOQ/0 #_zpg1_nCBEeKdD9Oad6OUOQ http://SysID_Profile.ServiceProfile/schemas/SimpleTypes/_zddWsnCBEeKdD9Oad6OUOQ/0 #_zpg2fXCBEeKdD9Oad6OUOQ http://schema.omg.org/spec/UML/2.1/StandardProfileL2 http://schema.omg.org/spec/UML/2.1/StandardProfileL2.xmi#_yzU58YinEdqtvbnfB2L_5w http://schema.omg.org/spec/UML/2.1 http://www.eclipse.org/uml2/2.0.0/UML";
}
そして、このコンソール アプリケーション
class Program
{
static void Main(string[] args)
{
var xmi = new XMIElement();
xmi.Version = "2.1";
xmi.SchemaLocation = XmiStrings.SchemaLocation;
var serializer = new XmlSerializer(typeof(XMIElement));
var writer = new StreamWriter("test.xml");
serializer.Serialize(writer, xmi, GetNamespaces());
}
private static XmlSerializerNamespaces GetNamespaces()
{
var ns = new XmlSerializerNamespaces();
ns.Add("xmi", XmiStrings.XmiNamespace);
ns.Add("xsi", XmiStrings.XsiNamespace);
ns.Add("PackageTypes", XmiStrings.PackageTypesNamespace);
ns.Add("RHP", XmiStrings.RHPNamespace);
ns.Add("RhapsodyProfile", XmiStrings.RhapsodyProfileNamespace);
ns.Add("ServiceProfile", XmiStrings.ServiceProfileNamespace);
ns.Add("SimpleTypes", XmiStrings.SimpleTypesNamespace);
ns.Add("Standard", XmiStrings.StandardNamespace);
ns.Add("ecore", XmiStrings.EcoreNamespace);
ns.Add("uml", XmiStrings.UmlNamespace);
return ns;
}
}
この出力を与える
<?xml version="1.0" encoding="utf-8"?>
<xmi:XMI xmlns:PackageTypes="http://SysID_Profile.ServiceProfile/schemas/PackageTypes/_zdnHsHCBEeKdD9Oad6OUOQ/0"
xmlns:RHP="http://RhapsodyStandardModel.RhpProperties/schemas/RHP/_zddWsXCBEeKdD9Oad6OUOQ/0"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
xmlns:ServiceProfile="http://SysID_Profile/schemas/ServiceProfile/_zdnHsXCBEeKdD9Oad6OUOQ/0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:RhapsodyProfile="http://RhapsodyStandardModel/schemas/RhapsodyProfile/_zddWsHCBEeKdD9Oad6OUOQ/0"
xmlns:SimpleTypes="http://SysID_Profile.ServiceProfile/schemas/SimpleTypes/_zddWsnCBEeKdD9Oad6OUOQ/0"
xmlns:Standard="http://schema.omg.org/spec/UML/2.1/StandardProfileL2"
xmlns:uml="http://schema.omg.org/spec/UML/2.1"
version="2.1"
xsi:schemaLocation="http://SysID_Profile.ServiceProfile/schemas/PackageTypes/_zdnHsHCBEeKdD9Oad6OUOQ/0 #_zpg3YHCBEeKdD9Oad6OUOQ http://RhapsodyStandardModel.RhpProperties/schemas/RHP/_zddWsXCBEeKdD9Oad6OUOQ/0 #_zpqBA3CBEeKdD9Oad6OUOQ http://RhapsodyStandardModel/schemas/RhapsodyProfile/_zddWsHCBEeKdD9Oad6OUOQ/0 #_zpp_o3CBEeKdD9Oad6OUOQ http://SysID_Profile/schemas/ServiceProfile/_zdnHsXCBEeKdD9Oad6OUOQ/0 #_zpg1_nCBEeKdD9Oad6OUOQ http://SysID_Profile.ServiceProfile/schemas/SimpleTypes/_zddWsnCBEeKdD9Oad6OUOQ/0 #_zpg2fXCBEeKdD9Oad6OUOQ http://schema.omg.org/spec/UML/2.1/StandardProfileL2 http://schema.omg.org/spec/UML/2.1/StandardProfileL2.xmi#_yzU58YinEdqtvbnfB2L_5w http://schema.omg.org/spec/UML/2.1 http://www.eclipse.org/uml2/2.0.0/UML"
xmlns:xmi="http://schema.omg.org/spec/XMI/2.1" />
私の質問は、XMI 要素と SchemaLocation の両方が正しく表示されているのに、バージョン属性が xmi:version="2.1" として表示されないのはなぜですか?