XmlSerializationWriter.cs 20 KB

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