本文整理汇总了C#中System.Xml.Linq.XDocument.CreateNavigator方法的典型用法代码示例。如果您正苦于以下问题:C# XDocument.CreateNavigator方法的具体用法?C# XDocument.CreateNavigator怎么用?C# XDocument.CreateNavigator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Linq.XDocument
的用法示例。
在下文中一共展示了XDocument.CreateNavigator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MakeHCFiles
public void MakeHCFiles(XDocument model)
{
using (var writer = new StreamWriter(Path.Combine(Path.GetTempPath(), m_database + "HCInput.xml")))
InputTransform.Transform(model.CreateNavigator(), null, writer);
using (var writer = new StreamWriter(Path.Combine(Path.GetTempPath(), m_database + "gram.txt")))
GrammarTransform.Transform(model.CreateNavigator(), null, writer);
// TODO: Putting this here is not necessarily efficient because it happens every time
// the parser is run. It would be more efficient to run this only when the user
// is trying a word. But we need the "model" to apply this transform and it is
// available here, so we're doing this for now.
using (var writer = new StreamWriter(Path.Combine(Path.GetTempPath(), m_database + "XAmpleWordGrammarDebugger.xsl")))
GrammarDebuggingTransform.Transform(model.CreateNavigator(), null, writer);
}
示例2: ValidationEvaluator
/// <summary>
/// Creates a new instance of the ValidationEvaluator containing the
/// the validation schema and a specific XML document to be validated.
/// </summary>
/// <param name="schema">Validation schema. Must not be null.</param>
/// <param name="xInstance">An instance of an XML document to be validated.
/// Must not be null.</param>
/// <param name="fullValidation">Indicates whether to validate the
/// whole document regardless of any assertion, or to stop validation at
/// the first assertion.</param>
public ValidationEvaluator(Schema schema, XDocument xInstance, bool fullValidation)
{
this.schema = schema;
this.xInstance = xInstance;
this.fullValidation = fullValidation;
this.xNavigator = xInstance.CreateNavigator();
}
示例3: Feedback
public AjaxResult Feedback(string email, string message, string additionalInfo)
{
try
{
this.HandleCall ();
if (!Utils.ValidateRequired (email, message) || !Utils.ValidateEmail (email))
return AjaxResult.WrongParametersOrHackAttempt;
XDocument xml = new XDocument (
new XElement ("Root",
new XElement ("Email", Utils.RemoveHtmlTagsAndTrim (email, false)),
new XElement ("Message", Utils.RemoveHtmlTagsAndTrim (message, true)),
new XElement ("AdditionalInfo", Utils.RemoveHtmlTagsAndTrim (additionalInfo, true))
)
);
if (this.Context.Request.Browser != null)
xml.Root.Add (new XElement ("Browser", this.Context.Request.Browser.Platform + " " + this.Context.Request.Browser.Browser + " " + this.Context.Request.Browser.Version));
if (this.Context.Request.UserAgent != null)
xml.Root.Add (new XElement ("UserAgent", this.Context.Request.UserAgent));
if (this.Context.Request.UserHostAddress != null)
xml.Root.Add (new XElement ("UserHostAddress", this.Context.Request.UserHostAddress));
Utils.SendMailXslt (xml.CreateNavigator (), "~/Xslt/EmailFeedback.xslt", ConfigurationManager.AppSettings["SupportEmail"]);
return AjaxResult.Success;
}
catch (Exception ex)
{
return this.HandleException (ex);
}
}
示例4: SendBodyAsync
protected override async Task SendBodyAsync(IRequestContext context)
{
if (Xslt != null) {
if (Model is XDocument)
await TransformAsync(context, ((XDocument)Model).CreateNavigator());
else if (Model is IXPathNavigable)
await TransformAsync(context, ((IXPathNavigable)Model));
else {
var ser = Serializer ?? new XmlSerializer(Model.GetType());
var doc = new XDocument();
using (var writer = doc.CreateWriter())
ser.Serialize(writer, Model);
await TransformAsync(context, doc.CreateNavigator());
}
}
else {
using (var writer = context.Response.GetStreamWriter()) {
if (Model is XDocument)
((XDocument)Model).Save(writer);
else if (Model is XmlDocument)
((XmlDocument)Model).Save(writer);
else if (Model is IXPathNavigable)
using (var xWriter = new XmlTextWriter(writer))
((IXPathNavigable)Model).CreateNavigator().WriteSubtree(xWriter);
else
(Serializer ?? new XmlSerializer(Model.GetType()))
.Serialize(writer, Model);
}
}
}
示例5: GetPersonInfo
public Stream GetPersonInfo(string id)
{
int personId = 0;
int.TryParse(id, out personId);
Person personFound = persons.FirstOrDefault(p => p.Id == personId);
if (WebOperationContext.Current != null)
WebOperationContext.Current.OutgoingResponse.ContentType = "text/html";
var reader = new StringReader(Resource.Style);
XmlReader xreader = XmlReader.Create(reader);
var xslt = new XslCompiledTransform(false);
xslt.Load(xreader);
var serializer = new XmlSerializer(typeof(Person));
var doc = new XDocument();
using (XmlWriter writer = doc.CreateWriter())
{
if (personFound != null)
serializer.Serialize(writer, personFound);
}
var outputWriter = new StringWriter();
xslt.Transform(doc.CreateNavigator(), null, outputWriter);
string htmlEmailText = outputWriter.ToString();
var encoding = new System.Text.ASCIIEncoding();
var stream = new MemoryStream(encoding.GetBytes(htmlEmailText));
return stream;
}
示例6: XmlNamespaceManagerEnhanced
public XmlNamespaceManagerEnhanced(XDocument doc)
: base(doc.CreateReader().NameTable)
{
var ns = doc.Root.GetDefaultNamespace();
if (ns != null && !string.IsNullOrWhiteSpace(ns.NamespaceName))
{
this.defaultNamespace = ns.NamespaceName;
AddNamespace(Common.DefaultNamespace, this.defaultNamespace);
}
var nslist = new Dictionary<string, string>();
var nav = doc.CreateNavigator();
while (nav.MoveToFollowing(XPathNodeType.Element))
{
var newFoundNapespaces = nav.GetNamespacesInScope(XmlNamespaceScope.All).Where(a => !nslist.ContainsKey(a.Key) && !this.HasNamespace(a.Key));
foreach (var item in newFoundNapespaces)
{
nslist.Add(item.Key, item.Value);
}
}
foreach (var item in nslist)
{
if (string.IsNullOrWhiteSpace(item.Key))
continue;
AddNamespace(item.Key, item.Value);
}
}
示例7: FindUnknownParentKeys
private string[] FindUnknownParentKeys(XDocument xmlDocument)
{
var pathNavigator = xmlDocument.CreateNavigator();
var issueKeyList = pathNavigator.Select ("//key").Cast<XPathNavigator>().Select (n => n.Value).Distinct();
var parentKeyList = pathNavigator.Select ("//parent").Cast<XPathNavigator>().Select (n => n.Value).Distinct();
return parentKeyList.Except (issueKeyList).ToArray();
}
示例8: Do
/// <summary>
/// выполнить конвертацию структуры
/// </summary>
public void Do()
{
try
{
SendMessage("\n- Конвертация структуры курса");
XDocument doc = new XDocument(course);
doc.Document.Declaration = new XDeclaration("1.0", "utf-8", "true");
XPathNavigator nv = doc.CreateNavigator();
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(convParams.ContentShemePath);
XsltArgumentList xslArg = new XsltArgumentList();
xslArg.AddParam("itemsPath", "", convParams.RootFolderName);
string outFile = Path.Combine(convParams.OutputAbsPath, convParams.StartFileName);
using (FileStream fs = new FileStream(outFile, FileMode.Create))
{
xslt.Transform(nv, xslArg, fs);
}
}
catch(Exception ex)
{
LastError = ex.Message;
throw new Exception("Исключение при конвертации структуры курса: "+ex.Message);
}
}
示例9: GetChildIterator
private XPathNodeIterator GetChildIterator(XDocument packet)
{
var xpathNavigator = packet.CreateNavigator();
xpathNavigator.MoveToRoot();
xpathNavigator.MoveToFirstChild();
return xpathNavigator.SelectChildren(XPathNodeType.Element);
}
示例10: GetInputXml
private IXPathNavigable GetInputXml()
{
var xml = new XDocument(new XElement("x", new XElement("y", "sds")));
//XmlDocument xml = new XmlDocument();
//xml.LoadXml("<x><y>sds</y></x>");
return xml.CreateNavigator();
}
示例11: GenerateQuickXml
public void GenerateQuickXml(TextWriter writer, XDocument xml)
{
var nav = xml.CreateNavigator();
if(xml.Declaration != null)
writer.WriteLine("?{0} {1}", xml.Declaration.Version, xml.Declaration.Encoding);
Traverse(writer, nav);
}
示例12: Transform
public string Transform(Mediator mediator, XDocument doc, string baseName, XsltArgumentList args)
{
var cache = (FdoCache) mediator.PropertyTable.GetValue("cache");
SetWritingSystemBasedArguments(cache, mediator, args);
args.AddParam("prmIconPath", "", IconPath);
string filePath = Path.Combine(Path.GetTempPath(), cache.ProjectId.Name + baseName + ".htm");
using (var writer = new StreamWriter(filePath))
m_transform.Transform(doc.CreateNavigator(), args, writer);
return filePath;
}
示例13: GetReady
public void GetReady ()
{
document = XDocument.Parse ("<foo><bar/><baz/><qux/><squonk/></foo>");
navigator = document.CreateNavigator ();
document2 = XDocument.Parse ("<foo><bar baz='1'/><bar baz='2'/><bar baz='3'/></foo>");
navigator2 = document2.CreateNavigator ();
document3 = XDocument.Parse ("<foo><bar/><baz/><qux/></foo>");
navigator3 = document3.CreateNavigator ();
}
示例14: ProfileFromTwitter
internal static LoginProfile ProfileFromTwitter(XDocument info)
{
XPathNavigator nav = info.CreateNavigator();
var profile = new LoginProfile
{
Name = nav.SelectNodeValue("//screen_name"),
DisplayName = nav.SelectNodeValue("//name"),
Avatar = nav.SelectNodeValue("//profile_image_url"),
TimeZone = nav.SelectNodeValue("//time_zone"),
Locale = nav.SelectNodeValue("//lang"),
Id = nav.SelectNodeValue("//id"),
Link = nav.SelectNodeValue("//url"),
Provider = ProviderConstants.Twitter
};
return profile;
}
示例15: saveTestCoreFunctionString
public void saveTestCoreFunctionString ()
{
document = XDocument.Parse ("<foo>hello<bar>world</bar><baz>how are you</baz></foo>");
navigator = document.CreateNavigator ();
Assert.AreEqual ("world", navigator.Evaluate ("string(/foo/*)").ToString (), "#1");
Assert.AreEqual ("NaN", navigator.Evaluate ("string(0 div 0)").ToString (), "#2");
try {
navigator.Evaluate ("string(+0)");
Assert.Fail ("Expected an XPathException to be thrown.");
} catch (XPathException) {}
Assert.AreEqual ("0", navigator.Evaluate ("string(-0)").ToString (), "#3");
Assert.AreEqual ("Infinity", navigator.Evaluate ("string(1 div 0)").ToString (), "#4");
Assert.AreEqual ("-Infinity", navigator.Evaluate ("string(-1 div 0)").ToString (), "#5");
Assert.AreEqual ("45", navigator.Evaluate ("string(45)").ToString (), "#6");
Assert.AreEqual ("-22", navigator.Evaluate ("string(-22)").ToString (), "#7");
Assert.AreEqual ("0.25", navigator.Evaluate ("string(.25)").ToString (), "#8");
Assert.AreEqual ("-0.25", navigator.Evaluate ("string(-.25)").ToString (), "#9");
Assert.AreEqual ("2", navigator.Evaluate ("string(2.0)").ToString (), "#10");
Assert.AreEqual ("2.01", navigator.Evaluate ("string(2.01)").ToString (), "#11");
Assert.AreEqual ("-3", navigator.Evaluate ("string(-3.0)").ToString (), "#12");
Assert.AreEqual ("3.45", navigator.Evaluate ("string(3.45)").ToString (), "#13");
// Wonder what this will look like under a different platform.
Assert.AreEqual("0.33333333333333331", navigator.Evaluate ("string(1 div 3)").ToString (), "#14");
}