コード例 #1
0
 public static string ToHTML(this IXML obj)
 {
     try
     {
         if (obj == null)
         {
             return(null);
         }
         XslCompiledTransform trans = GetTransform(obj);
         using (MemoryStream mem = obj.ToXMLStream())
         {
             RemoveDescription(mem);
             mem.Seek(0, SeekOrigin.Begin);
             XmlReader xr = XmlReader.Create(mem);
             using (StringWriter textWriter = new StringWriter())
             {
                 using (XmlWriter xw = XmlWriter.Create(textWriter))
                 {
                     trans.Transform(xr, xw);
                     return(textWriter.ToString());
                 }
             }
         }
     }
     catch (Exception ex)
     {
         return(Error(ex));
     }
 }
コード例 #2
0
        public void ContainsOnlyQueriedNodes()
        {
            IXML xml  = new XMLCursor("<t6><z9 a='433'><item>a</item><item>b</item></z9><z9 a='432'><item>c</item></z9></t6>");
            IXML root = xml.Nodes("/t6/z9[@a='433']")[0];

            Assert.Empty(root.Values("/z9[@a='432']"));
        }
コード例 #3
0
 /// <summary>
 /// metodo de la interfaz IContainer donde agrega un elemento de tipo
 /// IXML en este caso un level a la lista de niveles.
 /// </summary>
 /// <param name="ixml"> recibe un IXML para agregar a la lista. </param>
 public void Add(IXML ixml)
 {
     if (ixml is Level)
     {
         this.ListLevel.Add((Level)ixml);
     }
 }
コード例 #4
0
 /// <summary>
 /// metodo de la interfaz IContainer donde agrega un elemento de tipo
 /// IXML en este caso una Screen a la lista de Screen.
 /// </summary>
 /// <param name="ixml"> recibe un IXML para agregar a la lista. </param>
 public void Add(IXML ixml)
 {
     if (ixml is Screen)
     {
         this.ScreenList.Add((Screen)ixml);
     }
 }
コード例 #5
0
 /// <summary>
 /// metodo de la interfaz IContainer donde agrega un elemento de tipo
 /// IXML en este caso un Element a la lista de Elements.
 /// </summary>
 /// <param name="ixml"> recibe un IXML para agregar a la lista. </param>
 public void Add(IXML ixml)
 {
     if (ixml is Element)
     {
         this.ElementList.Add((Element)ixml);
     }
 }
コード例 #6
0
 /// <summary> Patched XML.</summary>
 /// <param name="xml"> XML to patch </param>
 /// <param name="xambler"> Patching Xambler </param>
 public XMLPatched(IXML xml, Xambler xambler) : this(
         new ScalarOf <XNode>(
             () => xml.AsNode()
             ),
         xambler
         )
 {
 }
コード例 #7
0
 public void Show(IXML id)
 {
     current = result.FindIndex(s => s == id);
     if (current < 0)
     {
         Show(0);
     }
     Show(current);
 }
コード例 #8
0
 /// <summary>
 /// Texts, extracted from a xml with xpath.
 /// </summary>
 public XMLTexts(IXML xml, string xpath) : base(() =>
                                                new Mapped <string, IText>(
                                                    str => new Atoms.Text.TextOf(str),
                                                    xml.Values(xpath)
                                                    ),
                                                false
                                                )
 {
 }
コード例 #9
0
 private void ShowHTML(IXML o)
 {
     webBrowser1.Navigate("about:blank");
     webBrowser1.Document.OpenNew(true);
     webBrowser1.Document.Write(o.ToHTML());
     webBrowser1.Refresh();
     counter.Text = (current + 1) + "/" + result.Count;
     this.Show();
 }
コード例 #10
0
        public void AppliesXpathToClonedNode()
        {
            IXML xml  = new XMLCursor("<t6><z9 a='433'/></t6>");
            IXML root = xml.Nodes("/t6")[0];

            Assert.Equal(
                "433",
                root.Values("//z9/@a")[0]
                );
        }
コード例 #11
0
 /// <summary>
 /// Number extracted from an xml using xpath.
 /// </summary>
 public XMLNumber(IXML xml, string xpath, IFormatProvider provider)
 {
     this.number =
         new ScalarOf <INumber>(() =>
                                new NumberOf(
                                    new XMLString(xml, xpath).Value(),
                                    provider
                                    )
                                );
 }
コード例 #12
0
 /// <summary>
 /// A Response containing the given status, reason and a body from the given xml.
 /// </summary>
 public Of(int status, string reason, IXML body, params IMapInput[] extraParts) : base(() =>
                                                                                       new Response.Of(
                                                                                           new Status(status),
                                                                                           new Reason(reason),
                                                                                           new Body(body),
                                                                                           new Parts.Joined(extraParts)
                                                                                           ),
                                                                                       live: false
                                                                                       )
 {
 }
コード例 #13
0
        public static bool deserializar(IXML archivo, out object obj)
        {
            bool respuesta = false;

            if (archivo.Leer(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\persona.xml", out obj))
            {
                respuesta = true;
            }

            return(respuesta);
        }
コード例 #14
0
        public static bool serializar(IXML archivo)
        {
            bool respuesta = false;

            if (archivo.Guardar(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\persona.xml"))
            {
                respuesta = true;
            }

            return(respuesta);
        }
コード例 #15
0
 private bool Match(IXML r, List <string> match, bool onlyName)
 {
     foreach (string s in match)
     {
         if (!r.Matches(s, onlyName))
         {
             return(false);
         }
     }
     return(true);
 }
コード例 #16
0
 public static bool Deserializar(IXML x, out object o)
 {
     try
     {
         x.Leer("test.xml", out o);
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
コード例 #17
0
ファイル: Serializadora.cs プロジェクト: murraydemian/C-Sharp
 public static bool Serializar(IXML item)
 {
     try
     {
         item.Guardar(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) +
                      @"\DatosClase20\textoXML.xml");
         return(true);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
コード例 #18
0
        public void PreservesDomStructureWhenXpath()
        {
            IXML doc =
                new XMLCursor(
                    "<root><item1/><item2/><item3/></root>"
                    );

            IXML item = doc.Nodes("/root/item2")[0];

            Assert.Equal(
                "root",
                item.Nodes("..")[0].Values("name()")[0]);
        }
コード例 #19
0
 /// <summary>
 /// A string in a document, retrieved by xpath.
 /// </summary>
 public XMLString(IXML xml, string xpath) :
     this
     (
         xml,
         xpath,
         () =>
 {
     throw new ArgumentException(
         $"Cannot retrieve single value with XPath '{xpath}', because it had no results in document{Environment.NewLine}'{xml.AsNode().ToString()}'."
         );
 }
     )
 { }
コード例 #20
0
        public static bool Serializar(IXML x)
        {
            try
            {
                x.Guardar("test.xml");
                return(true);
            }
            catch (Exception)
            {
                return(false);

                throw;
            }
        }
コード例 #21
0
ファイル: Serializadora.cs プロジェクト: murraydemian/C-Sharp
 public static bool Deserializar(IXML item, out object obj)
 {
     try
     {
         item.Leer(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) +
                   @"\DatosClase20\textoXML.xml");
         obj = item;
         return(true);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
コード例 #22
0
        public static InfoPage Show(IXML obj, Command cmd = null, string cmdText = "Do")
        {
            InfoPage Instance = new InfoPage(obj);

            if (cmd != null)
            {
                Instance.ToolbarItems.Add(new ToolbarItem()
                {
                    Command          = cmd,
                    CommandParameter = obj,
                    Text             = cmdText
                });
            }
            return(Instance);
        }
コード例 #23
0
        /// <summary>
        /// The XML transformed to simple text, no XML document.
        /// </summary>
        /// <param name="xml">input XML</param>
        /// <returns>transformed output</returns>
        public string TransformedToText(IXML xml)
        {
            StringBuilder sb = new StringBuilder();

            this.ErrorHandled(() =>
            {
                using (var writer = new StringWriter(sb))
                {
                    this.Xslt().Transform(
                        xml.AsNode().CreateReader(),
                        Params(),
                        writer
                        );
                }
            });

            return(sb.ToString());
        }
コード例 #24
0
        private static XslCompiledTransform GetTransform(IXML t)
        {
            if (t == null)
            {
                return(null);
            }
            if (Transforms.ContainsKey(t.GetType()))
            {
                return(Transforms[t.GetType()]);
            }
            XslCompiledTransform trans = new XslCompiledTransform();

            Transforms.Add(t.GetType(), trans);
            LoadTransform?.Invoke(trans, t);
            if (trans.OutputSettings == null)
            {
                throw new Exception("No Transform found for " + t.GetType());
            }
            return(trans);
        }
コード例 #25
0
 private InfoPage(IXML obj)
 {
     InitializeComponent();
     BindingContext = this;
     Obj            = obj;
     if (Obj is IOGLElement o)
     {
         Title = o.Name;
     }
     else if (Obj is Feature f)
     {
         Title = f.Name;
     }
     else if (Obj is DisplayPossession dp)
     {
         Title = dp.Name;
     }
     else
     {
         Title = "No Info";
     }
 }
コード例 #26
0
 /// <summary>
 /// A string in a document, retrieved by xpath.
 /// </summary>
 internal XMLString(IXML xml, string xpath, Func <string> fallback)
 {
     this.result = new ScalarOf <string>(() =>
     {
         var matches = xml.Values(xpath);
         var result  = string.Empty;
         if (matches.Count < 1)
         {
             result = fallback();
         }
         else if (matches.Count > 1)
         {
             throw new ArgumentException(
                 $"Cannot retrieve single value with XPath '{xpath}' because it resulted in multiple values in document{Environment.NewLine}'{xml.AsNode().ToString()}'."
                 );
         }
         else
         {
             result = matches[0];
         }
         return(result);
     });
 }
コード例 #27
0
        /// <summary>
        /// The transformed XML.
        /// </summary>
        /// <param name="xml">input XML</param>
        /// <returns>transformed output</returns>
        public IXML Transformed(IXML xml)
        {
            var transformed = new XDocument();
            var output      = new StringBuilder();
            var settings    = new XmlWriterSettings();

            settings.Indent           = false;
            settings.ConformanceLevel = ConformanceLevel.Auto;

            this.ErrorHandled(() =>
            {
                using (XmlWriter writer = XmlWriter.Create(output, settings))
                {
                    this.Xslt().Transform(
                        xml.AsNode().CreateReader(),
                        Params(),
                        writer
                        );
                }
            });

            return(new XMLCursor(output.ToString()));
        }
コード例 #28
0
 /// <summary>
 /// A string in a document, retrieved by xpath.
 /// </summary>
 public XMLString(IXML xml, string xpath, string def) : this(xml, xpath, () => def)
 {
 }
コード例 #29
0
 public string Convert(IXML obj)
 {
     return(obj.ToHTML());
 }
コード例 #30
0
 /// <summary>
 /// Strings in a document, retrieved by xpath.
 /// </summary>
 public XMLStrings(string xpath, IXML xml) : base(
         () => xml.Values(xpath),
         false
         )
 {
 }