XmlSerializationWriter.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  1. //
  2. // System.Xml.Serialization.XmlSerializationWriter.cs
  3. //
  4. // Author:
  5. // Tim Coleman ([email protected])
  6. // Lluis Sanchez Gual ([email protected])
  7. //
  8. // Copyright (C) Tim Coleman, 2002
  9. //
  10. using System;
  11. using System.Collections;
  12. using System.Text;
  13. using System.Xml;
  14. using System.Xml.Schema;
  15. using System.Runtime.Serialization;
  16. namespace System.Xml.Serialization {
  17. public abstract class XmlSerializationWriter {
  18. #region Fields
  19. ObjectIDGenerator idGenerator;
  20. int qnameCount;
  21. bool topLevelElement = false;
  22. ArrayList namespaces;
  23. XmlWriter writer;
  24. Queue referencedElements;
  25. Hashtable callbacks;
  26. const string xmlNamespace = "http://www.w3.org/2000/xmlns/";
  27. #endregion // Fields
  28. #region Constructors
  29. [MonoTODO]
  30. protected XmlSerializationWriter ()
  31. {
  32. qnameCount = 0;
  33. }
  34. #endregion // Constructors
  35. #region Properties
  36. protected ArrayList Namespaces {
  37. get { return namespaces; }
  38. set { namespaces = value; }
  39. }
  40. protected XmlWriter Writer {
  41. get { return writer; }
  42. set { writer = value; }
  43. }
  44. #endregion // Properties
  45. #region Methods
  46. internal void Initialize (XmlWriter writer)
  47. {
  48. this.writer = writer;
  49. }
  50. internal virtual void WriteObject (object ob)
  51. {
  52. throw new NotImplementedException ();
  53. }
  54. protected void AddWriteCallback (Type type, string typeName, string typeNs, XmlSerializationWriteCallback callback)
  55. {
  56. WriteCallbackInfo info = new WriteCallbackInfo ();
  57. info.Type = type;
  58. info.TypeName = typeName;
  59. info.TypeNs = typeNs;
  60. info.Callback = callback;
  61. if (callbacks == null) callbacks = new Hashtable ();
  62. callbacks.Add (type, info);
  63. }
  64. protected Exception CreateMismatchChoiceException (string value, string elementName, string enumValue)
  65. {
  66. string message = String.Format ("Value of {0} mismatches the type of {1}, you need to set it to {2}.", elementName, value, enumValue);
  67. return new InvalidOperationException (message);
  68. }
  69. protected Exception CreateUnknownAnyElementException (string name, string ns)
  70. {
  71. string message = String.Format ("The XML element named '{0}' from namespace '{1}' was not expected. The XML element name and namespace must match those provided via XmlAnyElementAttribute(s).", name, ns);
  72. return new InvalidOperationException (message);
  73. }
  74. protected Exception CreateUnknownTypeException (object o)
  75. {
  76. return CreateUnknownTypeException (o.GetType ());
  77. }
  78. protected Exception CreateUnknownTypeException (Type type)
  79. {
  80. string message = String.Format ("The type {0} may not be used in this context.", type);
  81. return new InvalidOperationException (message);
  82. }
  83. protected static string FromByteArrayBase64 (byte[] value)
  84. {
  85. return XmlCustomFormatter.FromByteArrayBase64 (value);
  86. }
  87. protected static string FromByteArrayHex (byte[] value)
  88. {
  89. return XmlCustomFormatter.FromByteArrayHex (value);
  90. }
  91. protected static string FromChar (char value)
  92. {
  93. return XmlCustomFormatter.FromChar (value);
  94. }
  95. protected static string FromDate (DateTime value)
  96. {
  97. return XmlCustomFormatter.FromDate (value);
  98. }
  99. protected static string FromDateTime (DateTime value)
  100. {
  101. return XmlCustomFormatter.FromDateTime (value);
  102. }
  103. protected static string FromEnum (long value, string[] values, long[] ids)
  104. {
  105. return XmlCustomFormatter.FromEnum (value, values, ids);
  106. }
  107. protected static string FromTime (DateTime value)
  108. {
  109. return XmlCustomFormatter.FromTime (value);
  110. }
  111. protected static string FromXmlName (string name)
  112. {
  113. return XmlCustomFormatter.FromXmlName (name);
  114. }
  115. protected static string FromXmlNCName (string ncName)
  116. {
  117. return XmlCustomFormatter.FromXmlNCName (ncName);
  118. }
  119. protected static string FromXmlNmToken (string nmToken)
  120. {
  121. return XmlCustomFormatter.FromXmlNmToken (nmToken);
  122. }
  123. protected static string FromXmlNmTokens (string nmTokens)
  124. {
  125. return XmlCustomFormatter.FromXmlNmTokens (nmTokens);
  126. }
  127. protected string FromXmlQualifiedName (XmlQualifiedName xmlQualifiedName)
  128. {
  129. if (xmlQualifiedName == null || xmlQualifiedName == XmlQualifiedName.Empty)
  130. return null;
  131. return GetQualifiedName (xmlQualifiedName.Name, xmlQualifiedName.Namespace);
  132. }
  133. private string GetId (object o, bool addToReferencesList)
  134. {
  135. if (idGenerator == null) idGenerator = new ObjectIDGenerator ();
  136. bool firstTime;
  137. long lid = idGenerator.GetId (o, out firstTime);
  138. return String.Format ("id{0}", lid);
  139. }
  140. bool AlreadyQueued (object ob)
  141. {
  142. if (idGenerator == null) return false;
  143. bool firstTime;
  144. idGenerator.HasId (ob, out firstTime);
  145. return !firstTime;
  146. }
  147. private string GetNamespacePrefix (string ns)
  148. {
  149. string prefix = Writer.LookupPrefix (ns);
  150. if (prefix == null)
  151. {
  152. prefix = String.Format ("q{0}", ++qnameCount);
  153. WriteAttribute ("xmlns", prefix, null, ns);
  154. }
  155. return prefix;
  156. }
  157. [MonoTODO ("Need to check for namespace conflicts before blindly allocating qN")]
  158. private string GetQualifiedName (string name, string ns)
  159. {
  160. string prefix = GetNamespacePrefix (ns);
  161. if (prefix == String.Empty)
  162. return name;
  163. else
  164. return String.Format ("{0}:{1}", prefix, name);
  165. }
  166. protected abstract void InitCallbacks ();
  167. protected void TopLevelElement ()
  168. {
  169. topLevelElement = true;
  170. }
  171. protected void WriteAttribute (string localName, byte[] value)
  172. {
  173. WriteAttribute (localName, String.Empty, value);
  174. }
  175. protected void WriteAttribute (string localName, string value)
  176. {
  177. WriteAttribute (String.Empty, localName, String.Empty, value);
  178. }
  179. protected void WriteAttribute (string localName, string ns, byte[] value)
  180. {
  181. if (value == null)
  182. return;
  183. Writer.WriteStartAttribute (localName, ns);
  184. WriteValue (value);
  185. Writer.WriteEndAttribute ();
  186. }
  187. protected void WriteAttribute (string localName, string ns, string value)
  188. {
  189. WriteAttribute (null, localName, ns, value);
  190. }
  191. protected void WriteAttribute (string prefix, string localName, string ns, string value)
  192. {
  193. if (value == null)
  194. return;
  195. Writer.WriteAttributeString (prefix, localName, ns, value);
  196. }
  197. protected void WriteElementEncoded (XmlNode node, string name, string ns, bool isNullable, bool any)
  198. {
  199. if (name != string.Empty)
  200. {
  201. if (node == null)
  202. {
  203. if (isNullable)
  204. WriteNullTagEncoded (name, ns);
  205. }
  206. else
  207. {
  208. Writer.WriteStartElement (name, ns);
  209. node.WriteTo (Writer);
  210. Writer.WriteEndElement ();
  211. }
  212. }
  213. else
  214. node.WriteTo (Writer);
  215. }
  216. protected void WriteElementLiteral (XmlNode node, string name, string ns, bool isNullable, bool any)
  217. {
  218. if (name != string.Empty)
  219. {
  220. if (node == null)
  221. {
  222. if (isNullable)
  223. WriteNullTagLiteral (name, ns);
  224. }
  225. else
  226. {
  227. Writer.WriteStartElement (name, ns);
  228. node.WriteTo (Writer);
  229. Writer.WriteEndElement ();
  230. }
  231. }
  232. else
  233. node.WriteTo (Writer);
  234. }
  235. protected void WriteElementQualifiedName (string localName, XmlQualifiedName value)
  236. {
  237. WriteElementQualifiedName (localName, String.Empty, value, null);
  238. }
  239. protected void WriteElementQualifiedName (string localName, string ns, XmlQualifiedName value)
  240. {
  241. WriteElementQualifiedName (localName, ns, value, null);
  242. }
  243. protected void WriteElementQualifiedName (string localName, XmlQualifiedName value, XmlQualifiedName xsiType)
  244. {
  245. WriteElementQualifiedName (localName, String.Empty, value, xsiType);
  246. }
  247. protected void WriteElementQualifiedName (string localName, string ns, XmlQualifiedName value, XmlQualifiedName xsiType)
  248. {
  249. localName = XmlCustomFormatter.FromXmlNCName (localName);
  250. WriteStartElement (localName, ns);
  251. if (xsiType != null) WriteXsiType (xsiType.Name, xsiType.Namespace);
  252. Writer.WriteString (FromXmlQualifiedName (value));
  253. WriteEndElement ();
  254. }
  255. protected void WriteElementString (string localName, string value)
  256. {
  257. WriteElementString (localName, String.Empty, value, null);
  258. }
  259. protected void WriteElementString (string localName, string ns, string value)
  260. {
  261. WriteElementString (localName, ns, value, null);
  262. }
  263. protected void WriteElementString (string localName, string value, XmlQualifiedName xsiType)
  264. {
  265. WriteElementString (localName, String.Empty, value, xsiType);
  266. }
  267. [MonoTODO ("Implement")]
  268. protected void WriteElementString (string localName, string ns, string value, XmlQualifiedName xsiType)
  269. {
  270. if (value == null) return;
  271. if (xsiType != null) {
  272. localName = XmlCustomFormatter.FromXmlNCName (localName);
  273. WriteStartElement (localName, ns);
  274. WriteXsiType (xsiType.Name, xsiType.Namespace);
  275. Writer.WriteString (value);
  276. WriteEndElement ();
  277. }
  278. else
  279. Writer.WriteElementString (localName, ns, value);
  280. }
  281. protected void WriteElementStringRaw (string localName, byte[] value)
  282. {
  283. WriteElementStringRaw (localName, String.Empty, value, null);
  284. }
  285. protected void WriteElementStringRaw (string localName, string value)
  286. {
  287. WriteElementStringRaw (localName, String.Empty, value, null);
  288. }
  289. protected void WriteElementStringRaw (string localName, byte[] value, XmlQualifiedName xsiType)
  290. {
  291. WriteElementStringRaw (localName, String.Empty, value, xsiType);
  292. }
  293. protected void WriteElementStringRaw (string localName, string ns, byte[] value)
  294. {
  295. WriteElementStringRaw (localName, ns, value, null);
  296. }
  297. protected void WriteElementStringRaw (string localName, string ns, string value)
  298. {
  299. WriteElementStringRaw (localName, ns, value, null);
  300. }
  301. protected void WriteElementStringRaw (string localName, string value, XmlQualifiedName xsiType)
  302. {
  303. WriteElementStringRaw (localName, String.Empty, value, null);
  304. }
  305. [MonoTODO ("Implement")]
  306. protected void WriteElementStringRaw (string localName, string ns, byte[] value, XmlQualifiedName xsiType)
  307. {
  308. throw new NotImplementedException ();
  309. }
  310. [MonoTODO ("Implement")]
  311. protected void WriteElementStringRaw (string localName, string ns, string value, XmlQualifiedName xsiType)
  312. {
  313. localName = XmlCustomFormatter.FromXmlNCName (localName);
  314. WriteStartElement (localName, ns);
  315. if (xsiType != null)
  316. WriteXsiType (xsiType.Name, xsiType.Namespace);
  317. Writer.WriteRaw (value);
  318. WriteEndElement ();
  319. }
  320. protected void WriteEmptyTag (string name)
  321. {
  322. WriteEmptyTag (name, String.Empty);
  323. }
  324. [MonoTODO ("Verify")]
  325. protected void WriteEmptyTag (string name, string ns)
  326. {
  327. name = XmlCustomFormatter.FromXmlName (name);
  328. WriteStartElement (name, ns);
  329. WriteEndElement ();
  330. }
  331. protected void WriteEndElement ()
  332. {
  333. WriteEndElement (null);
  334. }
  335. [MonoTODO ("Implement")]
  336. protected void WriteEndElement (object o)
  337. {
  338. Writer.WriteEndElement ();
  339. }
  340. protected void WriteId (object o)
  341. {
  342. WriteAttribute ("id", GetId (o, true));
  343. }
  344. protected void WriteNamespaceDeclarations (XmlSerializerNamespaces ns)
  345. {
  346. if (ns == null)
  347. return;
  348. ICollection namespaces = ns.Namespaces.Values;
  349. foreach (XmlQualifiedName qn in namespaces) {
  350. WriteAttribute ("xmlns", qn.Name, xmlNamespace, qn.Namespace);
  351. }
  352. }
  353. protected void WriteNullableQualifiedNameEncoded (string name, string ns, XmlQualifiedName value, XmlQualifiedName xsiType)
  354. {
  355. if (value != null)
  356. WriteElementQualifiedName (name, ns, value, xsiType);
  357. else
  358. WriteNullTagEncoded (name, ns);
  359. }
  360. protected void WriteNullableQualifiedNameLiteral (string name, string ns, XmlQualifiedName value)
  361. {
  362. if (value != null)
  363. WriteElementQualifiedName (name, ns, value);
  364. else
  365. WriteNullTagLiteral (name, ns);
  366. }
  367. protected void WriteNullableStringEncoded (string name, string ns, string value, XmlQualifiedName xsiType)
  368. {
  369. if (value != null)
  370. WriteElementString (name, ns, value, xsiType);
  371. else
  372. WriteNullTagEncoded (name, ns);
  373. }
  374. [MonoTODO ("Implement")]
  375. protected void WriteNullableStringEncodedRaw (string name, string ns, byte[] value, XmlQualifiedName xsiType)
  376. {
  377. throw new NotImplementedException ();
  378. }
  379. [MonoTODO ("Implement")]
  380. protected void WriteNullableStringEncodedRaw (string name, string ns, string value, XmlQualifiedName xsiType)
  381. {
  382. throw new NotImplementedException ();
  383. }
  384. protected void WriteNullableStringLiteral (string name, string ns, string value)
  385. {
  386. if (value != null)
  387. WriteElementString (name, ns, value, null);
  388. else
  389. WriteNullTagLiteral (name, ns);
  390. }
  391. [MonoTODO ("Implement")]
  392. protected void WriteNullableStringLiteralRaw (string name, string ns, byte[] value)
  393. {
  394. throw new NotImplementedException ();
  395. }
  396. [MonoTODO ("Implement")]
  397. protected void WriteNullableStringLiteralRaw (string name, string ns, string value)
  398. {
  399. throw new NotImplementedException ();
  400. }
  401. protected void WriteNullTagEncoded (string name)
  402. {
  403. WriteNullTagEncoded (name, String.Empty);
  404. }
  405. protected void WriteNullTagEncoded (string name, string ns)
  406. {
  407. WriteStartElement (name, ns);
  408. WriteAttribute ("xsi","null", XmlSchema.InstanceNamespace, "1");
  409. WriteEndElement ();
  410. }
  411. protected void WriteNullTagLiteral (string name)
  412. {
  413. WriteNullTagLiteral (name, String.Empty);
  414. }
  415. protected void WriteNullTagLiteral (string name, string ns)
  416. {
  417. WriteStartElement (name, ns);
  418. WriteAttribute ("xsi","nil", XmlSchema.InstanceNamespace, "true");
  419. WriteEndElement ();
  420. }
  421. protected void WritePotentiallyReferencingElement (string n, string ns, object o)
  422. {
  423. WritePotentiallyReferencingElement (n, ns, o, null, false, false);
  424. }
  425. protected void WritePotentiallyReferencingElement (string n, string ns, object o, Type ambientType)
  426. {
  427. WritePotentiallyReferencingElement (n, ns, o, ambientType, false, false);
  428. }
  429. protected void WritePotentiallyReferencingElement (string n, string ns, object o, Type ambientType, bool suppressReference)
  430. {
  431. WritePotentiallyReferencingElement (n, ns, o, ambientType, suppressReference, false);
  432. }
  433. protected void WritePotentiallyReferencingElement (string n, string ns, object o, Type ambientType, bool suppressReference, bool isNullable)
  434. {
  435. if (o == null)
  436. {
  437. if (isNullable) WriteNullTagEncoded (n, ns);
  438. return;
  439. }
  440. WriteStartElement (n, ns, o, true);
  441. CheckReferenceQueue ();
  442. if (callbacks.ContainsKey (o.GetType ()))
  443. {
  444. WriteCallbackInfo info = (WriteCallbackInfo) callbacks[o.GetType()];
  445. if (o.GetType ().IsEnum) {
  446. info.Callback (o);
  447. }
  448. else if (suppressReference) {
  449. Writer.WriteAttributeString ("id", GetId (o, false));
  450. if (ambientType != o.GetType ()) WriteXsiType(info.TypeName, info.TypeNs);
  451. info.Callback (o);
  452. }
  453. else {
  454. if (!AlreadyQueued (o)) referencedElements.Enqueue (o);
  455. Writer.WriteAttributeString ("href", "#" + GetId (o, true));
  456. }
  457. }
  458. else
  459. {
  460. // Must be a primitive type
  461. TypeData td = TypeTranslator.GetTypeData (o.GetType ());
  462. if (td.SchemaType != SchemaTypes.Primitive)
  463. throw new InvalidOperationException ("Invalid type: " + o.GetType().FullName);
  464. WriteXsiType(td.XmlType, XmlSchema.Namespace);
  465. Writer.WriteString (XmlCustomFormatter.ToXmlString (td, o));
  466. }
  467. WriteEndElement (o);
  468. }
  469. protected void WriteReferencedElements ()
  470. {
  471. if (referencedElements == null) return;
  472. if (callbacks == null) return;
  473. while (referencedElements.Count > 0)
  474. {
  475. object o = referencedElements.Dequeue ();
  476. TypeData td = TypeTranslator.GetTypeData (o.GetType ());
  477. WriteCallbackInfo info = (WriteCallbackInfo) callbacks[o.GetType()];
  478. WriteStartElement (info.TypeName, info.TypeNs, o, true);
  479. Writer.WriteAttributeString ("id", GetId (o, false));
  480. if (td.SchemaType != SchemaTypes.Array) // Array use its own "arrayType" attribute
  481. WriteXsiType(info.TypeName, info.TypeNs);
  482. info.Callback (o);
  483. WriteEndElement (o);
  484. }
  485. }
  486. protected void WriteReferencingElement (string n, string ns, object o)
  487. {
  488. WriteReferencingElement (n, ns, o, false);
  489. }
  490. protected void WriteReferencingElement (string n, string ns, object o, bool isNullable)
  491. {
  492. if (o == null)
  493. {
  494. if (isNullable) WriteNullTagEncoded (n, ns);
  495. return;
  496. }
  497. else
  498. {
  499. CheckReferenceQueue ();
  500. if (!AlreadyQueued (o)) referencedElements.Enqueue (o);
  501. Writer.WriteStartElement (n, ns);
  502. Writer.WriteAttributeString ("href", "#" + GetId (o, true));
  503. Writer.WriteEndElement ();
  504. }
  505. }
  506. void CheckReferenceQueue ()
  507. {
  508. if (referencedElements == null)
  509. {
  510. referencedElements = new Queue ();
  511. InitCallbacks ();
  512. }
  513. }
  514. protected void WriteSerializable (IXmlSerializable serializable, string name, string ns, bool isNullable)
  515. {
  516. if (serializable == null)
  517. {
  518. if (isNullable) WriteNullTagLiteral (name, ns);
  519. return;
  520. }
  521. else
  522. {
  523. Writer.WriteStartElement (name, ns);
  524. serializable.WriteXml (Writer);
  525. Writer.WriteEndElement ();
  526. }
  527. }
  528. protected void WriteStartDocument ()
  529. {
  530. if (Writer.WriteState == WriteState.Start)
  531. Writer.WriteStartDocument ();
  532. }
  533. protected void WriteStartElement (string name)
  534. {
  535. WriteStartElement (name, String.Empty, null, false);
  536. }
  537. protected void WriteStartElement (string name, string ns)
  538. {
  539. WriteStartElement (name, ns, null, false);
  540. }
  541. protected void WriteStartElement (string name, string ns, bool writePrefixed)
  542. {
  543. WriteStartElement (name, ns, null, writePrefixed);
  544. }
  545. protected void WriteStartElement (string name, string ns, object o)
  546. {
  547. WriteStartElement (name, ns, o, false);
  548. }
  549. [MonoTODO]
  550. protected void WriteStartElement (string name, string ns, object o, bool writePrefixed)
  551. {
  552. WriteState oldState = Writer.WriteState;
  553. if (writePrefixed && ns != string.Empty) {
  554. name = XmlCustomFormatter.FromXmlName (name);
  555. string prefix = Writer.LookupPrefix (ns);
  556. if (prefix == null) prefix = "q" + (++qnameCount);
  557. Writer.WriteStartElement (prefix, name, ns);
  558. } else
  559. Writer.WriteStartElement (name, ns);
  560. if (topLevelElement) {
  561. if (Writer.LookupPrefix (XmlSchema.Namespace) == null)
  562. WriteAttribute ("xmlns","xsd",xmlNamespace,XmlSchema.Namespace);
  563. if (Writer.LookupPrefix (XmlSchema.InstanceNamespace) == null)
  564. WriteAttribute ("xmlns","xsi",xmlNamespace,XmlSchema.InstanceNamespace);
  565. }
  566. topLevelElement = false;
  567. }
  568. protected void WriteTypedPrimitive (string name, string ns, object o, bool xsiType)
  569. {
  570. string value;
  571. TypeData td = TypeTranslator.GetTypeData (o.GetType ());
  572. name = XmlCustomFormatter.FromXmlName (name);
  573. Writer.WriteStartElement (name, ns);
  574. if (o is XmlQualifiedName)
  575. value = FromXmlQualifiedName ((XmlQualifiedName) o);
  576. else
  577. value = XmlCustomFormatter.ToXmlString (td, o);
  578. if (xsiType)
  579. {
  580. if (td.SchemaType != SchemaTypes.Primitive)
  581. throw new InvalidOperationException ("Invalid type: " + o.GetType().FullName);
  582. WriteXsiType (td.XmlType, XmlSchema.Namespace);
  583. }
  584. WriteValue (value);
  585. Writer.WriteEndElement ();
  586. }
  587. protected void WriteValue (byte[] value)
  588. {
  589. Writer.WriteBase64 (value, 0, value.Length);
  590. }
  591. protected void WriteValue (string value)
  592. {
  593. if (value != null)
  594. Writer.WriteString (value);
  595. }
  596. protected void WriteXmlAttribute (XmlNode node)
  597. {
  598. WriteXmlAttribute (node, null);
  599. }
  600. [MonoTODO ("Implement")]
  601. protected void WriteXmlAttribute (XmlNode node, object container)
  602. {
  603. if (!(node is XmlAttribute))
  604. throw new InvalidOperationException ("The node must be either type XmlAttribute or a derived type.");
  605. throw new NotImplementedException ();
  606. }
  607. protected void WriteXsiType (string name, string ns)
  608. {
  609. if (ns != null && ns != string.Empty)
  610. WriteAttribute ("type", XmlSchema.InstanceNamespace, GetQualifiedName (name, ns));
  611. else
  612. WriteAttribute ("type", XmlSchema.InstanceNamespace, name);
  613. }
  614. #endregion
  615. class WriteCallbackInfo
  616. {
  617. public Type Type;
  618. public string TypeName;
  619. public string TypeNs;
  620. public XmlSerializationWriteCallback Callback;
  621. }
  622. }
  623. }