CDISC ODM XML表現を使用する臨床試験プラットフォームであるOpenClinica用のXMLファイルを作成しようとしています。 私の問題は、私がしたXmlWriterによるXMLの非常に最初の要素を記述しようとすると、私はこの例外を持っている:XmlWriterで名前空間を書き換えるとXmlExceptionが発生する
An exception of type 'System.Xml.XmlException' occurred in System.Xml.dll but
was not handled in user code
Additional information: The prefix '' cannot be redefined from '' to
'http://www.cdisc.org/ns/odm/v1.3' within the same start element tag.
は、ここで私は私のファイルにしたいものです。
<ODM xmlns="http://www.cdisc.org/ns/odm/v1.3"
xmlns:OpenClinica="http://www.openclinica.org/ns/odm_ext_v130/v3.1"
xmlns:OpenClinicaRules="http://www.openclinica.org/ns/rules/v3.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
FileOID="testD20161121140900+0000"
Description="test"
CreationDateTime="2016-11-21T14:09:00+00:00"
FileType="Snapshot"
ODMVersion="1.3"
xsi:schemaLocation="http://www.cdisc.org/ns/odm/v1.3 OpenClinica-ODM1-3-0-OC2-0.xsd">
そして、ここでは私ですコード:
StringWriter swriter = new StringWriter();
XmlWriter writer = XmlWriter.Create(swriter);
writer.WriteStartElement("ODM");
writer.WriteAttributeString("xmlns", "http://www.cdisc.org/ns/odm/v1.3");
writer.WriteAttributeString("xmlns", "OpenClinica", null, "http://www.openclinica.org/ns/odm_ext_v130/v3.1");
writer.WriteAttributeString("xmlns","OpenClinicaRules",null, "http://www.openclinica.org/ns/rules/v3.1");
writer.WriteEndElement();
writer.Close();
return swriter.ToString();
私だけ「のxmlns:OpenClinica」書き込みしようとすると「のxmlns:OpenClinicaRules」属性を、それがうまくいっていますが、私はxmlnを書くしようとすると問題が発生しますs属性です。
何が問題なのですか?
あなたは、このような低レベルでこれを行うことが正当な理由がない限り、私はあなたがXMLまたは 'XmlSerializer'にLINQを使用することをお勧めしたいです。 –
はい、私は最後にXmlSerializerを使用します。ご意見ありがとうございます ! –