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); } }
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); }
public static string GetValueByXPath(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(e.ToString()); // ""; //"(error)"; } }
private bool IsSoapFailureMessage(string rspMsg) { if (!_context.ConfigMgr.Config.ThrowExceptionWhenReceiveFailureResponse) { return(false); } string val = XSLTExtension.GetValueByXPath(rspMsg, "/s:Envelope/s:Body/s:Fault", "s|http://schemas.xmlsoap.org/soap/envelope/"); bool isFailure = val != null && val.Length > 0; if (isFailure) { _context.Log.Write(LogType.Error, rspMsg); } return(isFailure); }