CustomXmlResolver.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using HTEXLib.Models.Inner;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Net;
  6. using System.Text;
  7. using System.Xml;
  8. namespace HTEXLib.COMM.Helpers
  9. {
  10. public class CustomXmlResolver : XmlResolver
  11. {
  12. public CustomXmlResolver() { }
  13. public override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn)
  14. {
  15. MemoryStream entityStream = null;
  16. switch (absoluteUri.Scheme)
  17. {
  18. case "custom-scheme":
  19. string absoluteUriOriginalString = absoluteUri.OriginalString;
  20. string ctgXsltEntityName = absoluteUriOriginalString.Substring(absoluteUriOriginalString.IndexOf(":") + 1);
  21. string entityXslt = "";
  22. // TODO: Replace the following with your own code to load data for referenced entities.
  23. switch (ctgXsltEntityName)
  24. {
  25. case "tokens.xsl":
  26. //entityXslt= System.IO.File.ReadAllText(@"D:\VSProjectCode\TEAMModelHTEX\HTEXMtahML\xslt\tokens.xsl");
  27. entityXslt = Globals.tokens;
  28. break;
  29. case "glayout.xsl":
  30. //entityXslt = System.IO.File.ReadAllText(@"D:\VSProjectCode\TEAMModelHTEX\HTEXMtahML\xslt\glayout.xsl");
  31. entityXslt = Globals.glayout;
  32. break;
  33. case "scripts.xsl":
  34. //entityXslt = System.IO.File.ReadAllText(@"D:\VSProjectCode\TEAMModelHTEX\HTEXMtahML\xslt\scripts.xsl");
  35. entityXslt = Globals.scripts;
  36. break;
  37. case "tables.xsl":
  38. //entityXslt = System.IO.File.ReadAllText(@"D:\VSProjectCode\TEAMModelHTEX\HTEXMtahML\xslt\tables.xsl");
  39. entityXslt = Globals.tables;
  40. break;
  41. case "entities.xsl":
  42. //entityXslt = System.IO.File.ReadAllText(@"D:\VSProjectCode\TEAMModelHTEX\HTEXMtahML\xslt\entities.xsl");
  43. entityXslt = Globals.entities;
  44. break;
  45. case "cmarkup.xsl":
  46. //entityXslt = System.IO.File.ReadAllText(@"D:\VSProjectCode\TEAMModelHTEX\HTEXMtahML\xslt\cmarkup.xsl");
  47. entityXslt = Globals.cmarkup;
  48. break;
  49. }
  50. UTF8Encoding utf8Encoding = new UTF8Encoding();
  51. byte[] entityBytes = utf8Encoding.GetBytes(entityXslt);
  52. entityStream = new MemoryStream(entityBytes);
  53. break;
  54. }
  55. return entityStream;
  56. }
  57. public override Uri ResolveUri(Uri baseUri, string relativeUri)
  58. {
  59. // You might want to resolve all reference URIs using a custom scheme.
  60. if (baseUri != null)
  61. return base.ResolveUri(baseUri, relativeUri);
  62. else
  63. return new Uri("custom-scheme:" + relativeUri);
  64. }
  65. }
  66. }