Exemple #1
0
        private XmlNode FindXmlNode(string xpath, string prefixes)
        {
            XmlNode node = null;

            if (prefixes == null || prefixes.Length < 1)
            {
                node = _doc.SelectSingleNode(xpath);
            }
            else
            {
                XmlNamespaceManager nsm = new XmlNamespaceManager(_doc.NameTable);
                XSLTExtension.FillXmlNamespaceManager(nsm, prefixes);

                //int i = 0;
                //string[] prefixList = prefixes.Split('|');
                //while (i < prefixList.Length)
                //{
                //    string prefix = prefixList[i].Trim();
                //    if (++i >= prefixList.Length) break;
                //    string nsURI = prefixList[i++].Trim();
                //    nsm.AddNamespace(prefix, nsURI);
                //}

                node = _doc.SelectSingleNode(xpath, nsm);
            }

            return(node);
        }
Exemple #2
0
        public bool TransformString(string sourceString, ref string targetString, XSLTExtensionType extType)
        {
            try
            {
                StringBuilder sb = new StringBuilder();
                using (StringWriter sw = new StringWriter(sb))
                {
                    using (StringReader sr = new StringReader(sourceString))
                    {
                        using (XmlTextReader xtr = new XmlTextReader(sr))
                        {
                            using (XmlTextWriter stw = new XmlTextWriter(sw))
                            {
                                stw.Formatting = Formatting.Indented;

                                XsltArgumentList arg = XSLTExtension.GetXsltArgumentList(extType, sourceString);
                                bool             res = TransformXmlWithExtension(xtr, stw, arg);

                                if (res)
                                {
                                    targetString = sb.ToString();
                                }
                                return(res);
                            }
                        }
                    }
                }
            }
            catch (Exception err)
            {
                NotifyError(err);
                return(false);
            }
        }
Exemple #3
0
        public string GetMessageKeyword(string xmlString, string xpath, string prefixDef)
        {
            if (xpath == null || xpath.Length < 1)
            {
                return("");
            }
            if (xmlString == null || xmlString.Length < 1)
            {
                return("");
            }

            try
            {
                using (StringReader sr = new StringReader(xmlString))
                {
                    XPathDocument  doc = new XPathDocument(sr);
                    XPathNavigator nvg = doc.CreateNavigator();

                    XmlNamespaceManager nsMgr = null;
                    if (prefixDef != null && prefixDef.Length > 0)
                    {
                        nsMgr = new XmlNamespaceManager(nvg.NameTable);
                        XSLTExtension.FillXmlNamespaceManager(nsMgr, prefixDef);
                    }

                    object o     = (nsMgr == null) ? nvg.Evaluate(xpath) : nvg.Evaluate(xpath, nsMgr);
                    string value = (o != null) ? o.ToString() : "";     //"(null)";

                    XPathNodeIterator i = o as XPathNodeIterator;
                    if (i != null)
                    {
                        StringBuilder sb = new StringBuilder();
                        while (i.MoveNext())
                        {
                            sb.Append(i.Current.Value); //.Append(';');
                        }
                        value = sb.ToString();          //.TrimEnd(';');
                    }

                    return(value);
                }
            }
            catch (Exception e)
            {
                _context.Log.Write(e);
                return("");  //"(error)";
            }
        }