XmlSerializationWriter.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  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 string.Empty;
  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. if (ns == String.Empty) {
  153. prefix = String.Empty;
  154. WriteAttribute ("xmlns", String.Empty);
  155. } else {
  156. prefix = String.Format ("q{0}", ++qnameCount);
  157. WriteAttribute ("xmlns", prefix, null, ns);
  158. }
  159. }
  160. return prefix;
  161. }
  162. [MonoTODO ("Need to check for namespace conflicts before blindly allocating qN")]
  163. private string GetQualifiedName (string name, string ns)
  164. {
  165. string prefix = GetNamespacePrefix (ns);
  166. if (prefix == String.Empty)
  167. return name;
  168. else
  169. return String.Format ("{0}:{1}", prefix, name);
  170. }
  171. protected abstract void InitCallbacks ();
  172. protected void TopLevelElement ()
  173. {
  174. topLevelElement = true;
  175. }
  176. protected void WriteAttribute (string localName, byte[] value)
  177. {
  178. WriteAttribute (localName, String.Empty, value);
  179. }
  180. protected void WriteAttribute (string localName, string value)
  181. {
  182. WriteAttribute (String.Empty, localName, String.Empty, value);
  183. }
  184. protected void WriteAttribute (string localName, string ns, byte[] value)
  185. {
  186. if (value == null)
  187. return;
  188. Writer.WriteStartAttribute (localName, ns);
  189. WriteValue (value);
  190. Writer.WriteEndAttribute ();
  191. }
  192. protected void WriteAttribute (string localName, string ns, string value)
  193. {
  194. WriteAttribute (null, localName, ns, value);
  195. }
  196. protected void WriteAttribute (string prefix, string localName, string ns, string value)
  197. {
  198. if (value == null)
  199. return;
  200. Writer.WriteAttributeString (prefix, localName, ns, value);
  201. }
  202. protected void WriteElementEncoded (XmlNode node, string name, string ns, bool isNullable, bool any)
  203. {
  204. if (name != string.Empty)
  205. {
  206. if (node == null)
  207. {
  208. if (isNullable)
  209. WriteNullTagEncoded (name, ns);
  210. }
  211. else
  212. {
  213. Writer.WriteStartElement (name, ns);
  214. node.WriteTo (Writer);
  215. Writer.WriteEndElement ();
  216. }
  217. }
  218. else
  219. node.WriteTo (Writer);
  220. }
  221. protected void WriteElementLiteral (XmlNode node, string name, string ns, bool isNullable, bool any)
  222. {
  223. if (name != string.Empty)
  224. {
  225. if (node == null)
  226. {
  227. if (isNullable)
  228. WriteNullTagLiteral (name, ns);
  229. }
  230. else
  231. {
  232. Writer.WriteStartElement (name, ns);
  233. node.WriteTo (Writer);
  234. Writer.WriteEndElement ();
  235. }
  236. }
  237. else
  238. node.WriteTo (Writer);
  239. }
  240. protected void WriteElementQualifiedName (string localName, XmlQualifiedName value)
  241. {
  242. WriteElementQualifiedName (localName, String.Empty, value, null);
  243. }
  244. protected void WriteElementQualifiedName (string localName, string ns, XmlQualifiedName value)
  245. {
  246. WriteElementQualifiedName (localName, ns, value, null);
  247. }
  248. protected void WriteElementQualifiedName (string localName, XmlQualifiedName value, XmlQualifiedName xsiType)
  249. {
  250. WriteElementQualifiedName (localName, String.Empty, value, xsiType);
  251. }
  252. protected void WriteElementQualifiedName (string localName, string ns, XmlQualifiedName value, XmlQualifiedName xsiType)
  253. {
  254. localName = XmlCustomFormatter.FromXmlNCName (localName);
  255. WriteStartElement (localName, ns);
  256. if (xsiType != null) WriteXsiType (xsiType.Name, xsiType.Namespace);
  257. Writer.WriteString (FromXmlQualifiedName (value));
  258. WriteEndElement ();
  259. }
  260. protected void WriteElementString (string localName, string value)
  261. {
  262. WriteElementString (localName, String.Empty, value, null);
  263. }
  264. protected void WriteElementString (string localName, string ns, string value)
  265. {
  266. WriteElementString (localName, ns, value, null);
  267. }
  268. protected void WriteElementString (string localName, string value, XmlQualifiedName xsiType)
  269. {
  270. WriteElementString (localName, String.Empty, value, xsiType);
  271. }
  272. [MonoTODO ("Implement")]
  273. protected void WriteElementString (string localName, string ns, string value, XmlQualifiedName xsiType)
  274. {
  275. if (value == null) return;
  276. if (xsiType != null) {
  277. localName = XmlCustomFormatter.FromXmlNCName (localName);
  278. WriteStartElement (localName, ns);
  279. WriteXsiType (xsiType.Name, xsiType.Namespace);
  280. Writer.WriteString (value);
  281. WriteEndElement ();
  282. }
  283. else
  284. Writer.WriteElementString (localName, ns, value);
  285. }
  286. protected void WriteElementStringRaw (string localName, byte[] value)
  287. {
  288. WriteElementStringRaw (localName, String.Empty, value, null);
  289. }
  290. protected void WriteElementStringRaw (string localName, string value)
  291. {
  292. WriteElementStringRaw (localName, String.Empty, value, null);
  293. }
  294. protected void WriteElementStringRaw (string localName, byte[] value, XmlQualifiedName xsiType)
  295. {
  296. WriteElementStringRaw (localName, String.Empty, value, xsiType);
  297. }
  298. protected void WriteElementStringRaw (string localName, string ns, byte[] value)
  299. {
  300. WriteElementStringRaw (localName, ns, value, null);
  301. }
  302. protected void WriteElementStringRaw (string localName, string ns, string value)
  303. {
  304. WriteElementStringRaw (localName, ns, value, null);
  305. }
  306. protected void WriteElementStringRaw (string localName, string value, XmlQualifiedName xsiType)
  307. {
  308. WriteElementStringRaw (localName, String.Empty, value, null);
  309. }
  310. [MonoTODO ("Implement")]
  311. protected void WriteElementStringRaw (string localName, string ns, byte[] value, XmlQualifiedName xsiType)
  312. {
  313. throw new NotImplementedException ();
  314. }
  315. [MonoTODO ("Implement")]
  316. protected void WriteElementStringRaw (string localName, string ns, string value, XmlQualifiedName xsiType)
  317. {
  318. localName = XmlCustomFormatter.FromXmlNCName (localName);
  319. WriteStartElement (localName, ns);
  320. if (xsiType != null)
  321. WriteXsiType (xsiType.Name, xsiType.Namespace);
  322. Writer.WriteRaw (value);
  323. WriteEndElement ();
  324. }
  325. protected void WriteEmptyTag (string name)
  326. {
  327. WriteEmptyTag (name, String.Empty);
  328. }
  329. [MonoTODO ("Verify")]
  330. protected void WriteEmptyTag (string name, string ns)
  331. {
  332. name = XmlCustomFormatter.FromXmlName (name);
  333. WriteStartElement (name, ns);
  334. WriteEndElement ();
  335. }
  336. protected void WriteEndElement ()
  337. {
  338. WriteEndElement (null);
  339. }
  340. [MonoTODO ("Implement")]
  341. protected void WriteEndElement (object o)
  342. {
  343. Writer.WriteEndElement ();
  344. }
  345. protected void WriteId (object o)
  346. {
  347. WriteAttribute ("id", GetId (o, true));
  348. }
  349. protected void WriteNamespaceDeclarations (XmlSerializerNamespaces ns)
  350. {
  351. if (ns == null)
  352. return;
  353. ICollection namespaces = ns.Namespaces.Values;
  354. foreach (XmlQualifiedName qn in namespaces) {
  355. WriteAttribute ("xmlns", qn.Name, xmlNamespace, qn.Namespace);
  356. }
  357. }
  358. protected void WriteNullableQualifiedNameEncoded (string name, string ns, XmlQualifiedName value, XmlQualifiedName xsiType)
  359. {
  360. if (value != null)
  361. WriteElementQualifiedName (name, ns, value, xsiType);
  362. else
  363. WriteNullTagEncoded (name, ns);
  364. }
  365. protected void WriteNullableQualifiedNameLiteral (string name, string ns, XmlQualifiedName value)
  366. {
  367. if (value != null)
  368. WriteElementQualifiedName (name, ns, value);
  369. else
  370. WriteNullTagLiteral (name, ns);
  371. }
  372. protected void WriteNullableStringEncoded (string name, string ns, string value, XmlQualifiedName xsiType)
  373. {
  374. if (value != null)
  375. WriteElementString (name, ns, value, xsiType);
  376. else
  377. WriteNullTagEncoded (name, ns);
  378. }
  379. [MonoTODO ("Implement")]
  380. protected void WriteNullableStringEncodedRaw (string name, string ns, byte[] value, XmlQualifiedName xsiType)
  381. {
  382. throw new NotImplementedException ();
  383. }
  384. [MonoTODO ("Implement")]
  385. protected void WriteNullableStringEncodedRaw (string name, string ns, string value, XmlQualifiedName xsiType)
  386. {
  387. throw new NotImplementedException ();
  388. }
  389. protected void WriteNullableStringLiteral (string name, string ns, string value)
  390. {
  391. if (value != null)
  392. WriteElementString (name, ns, value, null);
  393. else
  394. WriteNullTagLiteral (name, ns);
  395. }
  396. [MonoTODO ("Implement")]
  397. protected void WriteNullableStringLiteralRaw (string name, string ns, byte[] value)
  398. {
  399. throw new NotImplementedException ();
  400. }
  401. [MonoTODO ("Implement")]
  402. protected void WriteNullableStringLiteralRaw (string name, string ns, string value)
  403. {
  404. throw new NotImplementedException ();
  405. }
  406. protected void WriteNullTagEncoded (string name)
  407. {
  408. WriteNullTagEncoded (name, String.Empty);
  409. }
  410. protected void WriteNullTagEncoded (string name, string ns)
  411. {
  412. WriteStartElement (name, ns);
  413. WriteAttribute ("xsi","null", XmlSchema.InstanceNamespace, "1");
  414. WriteEndElement ();
  415. }
  416. protected void WriteNullTagLiteral (string name)
  417. {
  418. WriteNullTagLiteral (name, String.Empty);
  419. }
  420. protected void WriteNullTagLiteral (string name, string ns)
  421. {
  422. WriteStartElement (name, ns);
  423. WriteAttribute ("xsi","nil", XmlSchema.InstanceNamespace, "true");
  424. WriteEndElement ();
  425. }
  426. protected void WritePotentiallyReferencingElement (string n, string ns, object o)
  427. {
  428. WritePotentiallyReferencingElement (n, ns, o, null, false, false);
  429. }
  430. protected void WritePotentiallyReferencingElement (string n, string ns, object o, Type ambientType)
  431. {
  432. WritePotentiallyReferencingElement (n, ns, o, ambientType, false, false);
  433. }
  434. protected void WritePotentiallyReferencingElement (string n, string ns, object o, Type ambientType, bool suppressReference)
  435. {
  436. WritePotentiallyReferencingElement (n, ns, o, ambientType, suppressReference, false);
  437. }
  438. protected void WritePotentiallyReferencingElement (string n, string ns, object o, Type ambientType, bool suppressReference, bool isNullable)
  439. {
  440. if (o == null)
  441. {
  442. if (isNullable) WriteNullTagEncoded (n, ns);
  443. return;
  444. }
  445. WriteStartElement (n, ns, o, true);
  446. CheckReferenceQueue ();
  447. if (callbacks.ContainsKey (o.GetType ()))
  448. {
  449. WriteCallbackInfo info = (WriteCallbackInfo) callbacks[o.GetType()];
  450. if (o.GetType ().IsEnum) {
  451. info.Callback (o);
  452. }
  453. else if (suppressReference) {
  454. Writer.WriteAttributeString ("id", GetId (o, false));
  455. if (ambientType != o.GetType ()) WriteXsiType(info.TypeName, info.TypeNs);
  456. info.Callback (o);
  457. }
  458. else {
  459. if (!AlreadyQueued (o)) referencedElements.Enqueue (o);
  460. Writer.WriteAttributeString ("href", "#" + GetId (o, true));
  461. }
  462. }
  463. else
  464. {
  465. // Must be a primitive type
  466. TypeData td = TypeTranslator.GetTypeData (o.GetType ());
  467. if (td.SchemaType != SchemaTypes.Primitive)
  468. throw new InvalidOperationException ("Invalid type: " + o.GetType().FullName);
  469. WriteXsiType(td.XmlType, XmlSchema.Namespace);
  470. Writer.WriteString (XmlCustomFormatter.ToXmlString (td, o));
  471. }
  472. WriteEndElement (o);
  473. }
  474. protected void WriteReferencedElements ()
  475. {
  476. if (referencedElements == null) return;
  477. if (callbacks == null) return;
  478. while (referencedElements.Count > 0)
  479. {
  480. object o = referencedElements.Dequeue ();
  481. TypeData td = TypeTranslator.GetTypeData (o.GetType ());
  482. WriteCallbackInfo info = (WriteCallbackInfo) callbacks[o.GetType()];
  483. WriteStartElement (info.TypeName, info.TypeNs, o, true);
  484. Writer.WriteAttributeString ("id", GetId (o, false));
  485. if (td.SchemaType != SchemaTypes.Array) // Array use its own "arrayType" attribute
  486. WriteXsiType(info.TypeName, info.TypeNs);
  487. info.Callback (o);
  488. WriteEndElement (o);
  489. }
  490. }
  491. protected void WriteReferencingElement (string n, string ns, object o)
  492. {
  493. WriteReferencingElement (n, ns, o, false);
  494. }
  495. protected void WriteReferencingElement (string n, string ns, object o, bool isNullable)
  496. {
  497. if (o == null)
  498. {
  499. if (isNullable) WriteNullTagEncoded (n, ns);
  500. return;
  501. }
  502. else
  503. {
  504. CheckReferenceQueue ();
  505. if (!AlreadyQueued (o)) referencedElements.Enqueue (o);
  506. Writer.WriteStartElement (n, ns);
  507. Writer.WriteAttributeString ("href", "#" + GetId (o, true));
  508. Writer.WriteEndElement ();
  509. }
  510. }
  511. void CheckReferenceQueue ()
  512. {
  513. if (referencedElements == null)
  514. {
  515. referencedElements = new Queue ();
  516. InitCallbacks ();
  517. }
  518. }
  519. protected void WriteSerializable (IXmlSerializable serializable, string name, string ns, bool isNullable)
  520. {
  521. if (serializable == null)
  522. {
  523. if (isNullable) WriteNullTagLiteral (name, ns);
  524. return;
  525. }
  526. else
  527. {
  528. Writer.WriteStartElement (name, ns);
  529. serializable.WriteXml (Writer);
  530. Writer.WriteEndElement ();
  531. }
  532. }
  533. protected void WriteStartDocument ()
  534. {
  535. if (Writer.WriteState == WriteState.Start)
  536. Writer.WriteStartDocument ();
  537. }
  538. protected void WriteStartElement (string name)
  539. {
  540. WriteStartElement (name, String.Empty, null, false);
  541. }
  542. protected void WriteStartElement (string name, string ns)
  543. {
  544. WriteStartElement (name, ns, null, false);
  545. }
  546. protected void WriteStartElement (string name, string ns, bool writePrefixed)
  547. {
  548. WriteStartElement (name, ns, null, writePrefixed);
  549. }
  550. protected void WriteStartElement (string name, string ns, object o)
  551. {
  552. WriteStartElement (name, ns, o, false);
  553. }
  554. [MonoTODO]
  555. protected void WriteStartElement (string name, string ns, object o, bool writePrefixed)
  556. {
  557. WriteState oldState = Writer.WriteState;
  558. if (writePrefixed && ns != string.Empty) {
  559. name = XmlCustomFormatter.FromXmlName (name);
  560. string prefix = Writer.LookupPrefix (ns);
  561. if (prefix == null) prefix = "q" + (++qnameCount);
  562. Writer.WriteStartElement (prefix, name, ns);
  563. } else
  564. Writer.WriteStartElement (name, ns);
  565. if (topLevelElement) {
  566. WriteAttribute ("xmlns","xsd",xmlNamespace,XmlSchema.Namespace);
  567. WriteAttribute ("xmlns","xsi",xmlNamespace,XmlSchema.InstanceNamespace);
  568. }
  569. topLevelElement = false;
  570. }
  571. protected void WriteTypedPrimitive (string name, string ns, object o, bool xsiType)
  572. {
  573. string value;
  574. TypeData td = TypeTranslator.GetTypeData (o.GetType ());
  575. name = XmlCustomFormatter.FromXmlName (name);
  576. Writer.WriteStartElement (name, ns);
  577. if (o is XmlQualifiedName)
  578. value = FromXmlQualifiedName ((XmlQualifiedName) o);
  579. else
  580. value = XmlCustomFormatter.ToXmlString (td, o);
  581. if (xsiType)
  582. {
  583. if (td.SchemaType != SchemaTypes.Primitive)
  584. throw new InvalidOperationException ("Invalid type: " + o.GetType().FullName);
  585. WriteXsiType (td.XmlType, XmlSchema.Namespace);
  586. }
  587. WriteValue (value);
  588. Writer.WriteEndElement ();
  589. }
  590. protected void WriteValue (byte[] value)
  591. {
  592. Writer.WriteBase64 (value, 0, value.Length);
  593. }
  594. protected void WriteValue (string value)
  595. {
  596. if (value != null)
  597. Writer.WriteString (value);
  598. }
  599. protected void WriteXmlAttribute (XmlNode node)
  600. {
  601. WriteXmlAttribute (node, null);
  602. }
  603. [MonoTODO ("Implement")]
  604. protected void WriteXmlAttribute (XmlNode node, object container)
  605. {
  606. if (!(node is XmlAttribute))
  607. throw new InvalidOperationException ("The node must be either type XmlAttribute or a derived type.");
  608. throw new NotImplementedException ();
  609. }
  610. protected void WriteXsiType (string name, string ns)
  611. {
  612. if (ns != null && ns != string.Empty)
  613. WriteAttribute ("type", XmlSchema.InstanceNamespace, GetQualifiedName (name, ns));
  614. else
  615. WriteAttribute ("type", XmlSchema.InstanceNamespace, name);
  616. }
  617. #endregion
  618. class WriteCallbackInfo
  619. {
  620. public Type Type;
  621. public string TypeName;
  622. public string TypeNs;
  623. public XmlSerializationWriteCallback Callback;
  624. }
  625. }
  626. }