本文整理汇总了C#中System.Xml.XPath.XPathNavigator.MoveToFirstNamespace方法的典型用法代码示例。如果您正苦于以下问题:C# XPathNavigator.MoveToFirstNamespace方法的具体用法?C# XPathNavigator.MoveToFirstNamespace怎么用?C# XPathNavigator.MoveToFirstNamespace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XPath.XPathNavigator
的用法示例。
在下文中一共展示了XPathNavigator.MoveToFirstNamespace方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MoveToNamespaces
private void MoveToNamespaces (XPathNavigator nav)
{
XPathNodeIterator iter = nav.Select ("//e");
iter.MoveNext ();
nav.MoveTo (iter.Current);
Assert.AreEqual ("e", nav.Name, "#1");
nav.MoveToFirstNamespace ();
Assert.AreEqual ("x", nav.Name, "#2");
nav.MoveToNextNamespace ();
Assert.AreEqual ("xml", nav.Name, "#3");
}
示例2: WriteNode
// Copies the current node from the given XPathNavigator to the writer (including child nodes).
public virtual void WriteNode(XPathNavigator navigator, bool defattr)
{
if (navigator == null)
{
throw new ArgumentNullException(nameof(navigator));
}
int iLevel = 0;
navigator = navigator.Clone();
while (true)
{
bool mayHaveChildren = false;
XPathNodeType nodeType = navigator.NodeType;
switch (nodeType)
{
case XPathNodeType.Element:
WriteStartElement(navigator.Prefix, navigator.LocalName, navigator.NamespaceURI);
// Copy attributes
if (navigator.MoveToFirstAttribute())
{
do
{
IXmlSchemaInfo schemaInfo = navigator.SchemaInfo;
if (defattr || (schemaInfo == null || !schemaInfo.IsDefault))
{
WriteStartAttribute(navigator.Prefix, navigator.LocalName, navigator.NamespaceURI);
// copy string value to writer
WriteString(navigator.Value);
WriteEndAttribute();
}
} while (navigator.MoveToNextAttribute());
navigator.MoveToParent();
}
// Copy namespaces
if (navigator.MoveToFirstNamespace(XPathNamespaceScope.Local))
{
WriteLocalNamespaces(navigator);
navigator.MoveToParent();
}
mayHaveChildren = true;
break;
case XPathNodeType.Attribute:
// do nothing on root level attribute
break;
case XPathNodeType.Text:
WriteString(navigator.Value);
break;
case XPathNodeType.SignificantWhitespace:
case XPathNodeType.Whitespace:
WriteWhitespace(navigator.Value);
break;
case XPathNodeType.Root:
mayHaveChildren = true;
break;
case XPathNodeType.Comment:
WriteComment(navigator.Value);
break;
case XPathNodeType.ProcessingInstruction:
WriteProcessingInstruction(navigator.LocalName, navigator.Value);
break;
case XPathNodeType.Namespace:
// do nothing on root level namespace
break;
default:
Debug.Assert(false);
break;
}
if (mayHaveChildren)
{
// If children exist, move down to next level
if (navigator.MoveToFirstChild())
{
iLevel++;
continue;
}
else
{
// EndElement
if (navigator.NodeType == XPathNodeType.Element)
{
if (navigator.IsEmptyElement)
{
WriteEndElement();
}
else
{
WriteFullEndElement();
}
}
}
}
// No children
while (true)
//.........这里部分代码省略.........
示例3: XmlNamespaceNode
private void XmlNamespaceNode (XPathNavigator nav)
{
string xhtml = "http://www.w3.org/1999/xhtml";
string xmlNS = "http://www.w3.org/XML/1998/namespace";
nav.MoveToFirstChild ();
AssertNavigator ("#1", nav, XPathNodeType.Element,
"", "html", xhtml, "html", "test.", false, true, false);
Assert.IsTrue (nav.MoveToFirstNamespace (XPathNamespaceScope.Local));
AssertNavigator ("#2", nav, XPathNodeType.Namespace,
"", "", "", "", xhtml, false, false, false);
// Test difference between Local, ExcludeXml and All.
Assert.IsTrue (!nav.MoveToNextNamespace (XPathNamespaceScope.Local));
Assert.IsTrue (!nav.MoveToNextNamespace (XPathNamespaceScope.ExcludeXml));
// LAMESPEC: MS.NET 1.0 XmlDocument seems to have some bugs around here.
// see http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q316808
#if true
Assert.IsTrue (nav.MoveToNextNamespace (XPathNamespaceScope.All));
AssertNavigator ("#3", nav, XPathNodeType.Namespace,
"", "xml", "", "xml", xmlNS, false, false, false);
Assert.IsTrue (!nav.MoveToNextNamespace (XPathNamespaceScope.All));
#endif
// Test to check if MoveToRoot() resets Namespace node status.
nav.MoveToRoot ();
AssertNavigator ("#4", nav, XPathNodeType.Root, "", "", "", "", "test.", false, true, false);
nav.MoveToFirstChild ();
// Test without XPathNamespaceScope argument.
Assert.IsTrue (nav.MoveToFirstNamespace ());
Assert.IsTrue (nav.MoveToNextNamespace ());
AssertNavigator ("#5", nav, XPathNodeType.Namespace,
"", "xml", "", "xml", xmlNS, false, false, false);
// Test MoveToParent()
Assert.IsTrue (nav.MoveToParent ());
AssertNavigator ("#6", nav, XPathNodeType.Element,
"", "html", xhtml, "html", "test.", false, true, false);
nav.MoveToFirstChild (); // body
// Test difference between Local and ExcludeXml
Assert.IsTrue (!nav.MoveToFirstNamespace (XPathNamespaceScope.Local), "Local should fail");
Assert.IsTrue (nav.MoveToFirstNamespace (XPathNamespaceScope.ExcludeXml), "ExcludeXml should succeed");
AssertNavigator ("#7", nav, XPathNodeType.Namespace,
"", "", "", "", xhtml, false, false, false);
Assert.IsTrue (nav.MoveToNextNamespace (XPathNamespaceScope.All));
AssertNavigator ("#8", nav, XPathNodeType.Namespace,
"", "xml", "", "xml", xmlNS, false, false, false);
Assert.IsTrue (nav.MoveToParent ());
AssertNavigator ("#9", nav, XPathNodeType.Element,
"", "body", xhtml, "body", "test.", false, true, false);
nav.MoveToRoot ();
AssertNavigator ("#10", nav, XPathNodeType.Root, "", "", "", "", "test.", false, true, false);
}
示例4: CopyNamespaces
/// <summary>
/// Copy all namespaces of the specified type (in-scope, exclude-xml, local) in document order to output.
/// </summary>
private void CopyNamespaces(XPathNavigator navigator, XPathNamespaceScope nsScope) {
Debug.Assert(navigator.NodeType == XPathNodeType.Element, "Only elements have namespaces to copy");
// Default namespace undeclaration isn't included in navigator's namespace list, so add it now
if (navigator.NamespaceURI.Length == 0) {
Debug.Assert(navigator.LocalName.Length != 0, "xmlns:foo='' isn't allowed");
WriteNamespaceDeclarationUnchecked(string.Empty, string.Empty);
}
// Since the namespace list is arranged in reverse-document order, recursively reverse it.
if (navigator.MoveToFirstNamespace(nsScope)) {
CopyNamespacesHelper(navigator, nsScope);
navigator.MoveToParent();
}
}
示例5: CopyNode
/// <summary>
/// Copy the navigator subtree to the raw writer.
/// </summary>
private void CopyNode(XPathNavigator nav) {
XPathNodeType nodeType;
int iLevel = 0;
while (true) {
if (CopyShallowNode(nav)) {
nodeType = nav.NodeType;
if (nodeType == XPathNodeType.Element) {
// Copy attributes
if (nav.MoveToFirstAttribute()) {
do {
CopyShallowNode(nav);
}
while (nav.MoveToNextAttribute());
nav.MoveToParent();
}
// Copy namespaces in document order (navigator returns them in reverse document order)
XPathNamespaceScope nsScope = (iLevel == 0) ? XPathNamespaceScope.ExcludeXml : XPathNamespaceScope.Local;
if (nav.MoveToFirstNamespace(nsScope)) {
CopyNamespaces(nav, nsScope);
nav.MoveToParent();
}
this.xwrt.StartElementContent();
}
// If children exist, move down to next level
if (nav.MoveToFirstChild()) {
iLevel++;
continue;
}
else {
// EndElement
if (nav.NodeType == XPathNodeType.Element)
this.xwrt.WriteEndElement(nav.Prefix, nav.LocalName, nav.NamespaceURI);
}
}
// No children
while (true) {
if (iLevel == 0) {
// The entire subtree has been copied
return;
}
if (nav.MoveToNext()) {
// Found a sibling, so break to outer loop
break;
}
// No siblings, so move up to previous level
iLevel--;
nav.MoveToParent();
// EndElement
if (nav.NodeType == XPathNodeType.Element)
this.xwrt.WriteFullEndElement(nav.Prefix, nav.LocalName, nav.NamespaceURI);
}
}
}
示例6: WriteNode
public virtual void WriteNode (XPathNavigator navigator, bool defattr)
{
if (navigator == null)
throw new ArgumentNullException ("navigator");
switch (navigator.NodeType) {
case XPathNodeType.Attribute:
// no operation
break;
case XPathNodeType.Namespace:
// no operation
break;
case XPathNodeType.Text:
WriteString (navigator.Value);
break;
case XPathNodeType.SignificantWhitespace:
WriteWhitespace (navigator.Value);
break;
case XPathNodeType.Whitespace:
WriteWhitespace (navigator.Value);
break;
case XPathNodeType.Comment:
WriteComment (navigator.Value);
break;
case XPathNodeType.ProcessingInstruction:
WriteProcessingInstruction (navigator.Name, navigator.Value);
break;
case XPathNodeType.Root:
if (navigator.MoveToFirstChild ()) {
do {
WriteNode (navigator, defattr);
} while (navigator.MoveToNext ());
navigator.MoveToParent ();
}
break;
case XPathNodeType.Element:
WriteStartElement (navigator.Prefix, navigator.LocalName, navigator.NamespaceURI);
if (navigator.MoveToFirstNamespace (XPathNamespaceScope.Local)) {
do {
if (defattr || navigator.SchemaInfo == null || navigator.SchemaInfo.IsDefault)
WriteAttributeString (navigator.Prefix,
navigator.LocalName == String.Empty ? "xmlns" : navigator.LocalName,
"http://www.w3.org/2000/xmlns/",
navigator.Value);
} while (navigator.MoveToNextNamespace (XPathNamespaceScope.Local));
navigator.MoveToParent ();
}
if (navigator.MoveToFirstAttribute ()) {
do {
if (defattr || navigator.SchemaInfo == null || navigator.SchemaInfo.IsDefault)
WriteAttributeString (navigator.Prefix, navigator.LocalName, navigator.NamespaceURI, navigator.Value);
} while (navigator.MoveToNextAttribute ());
navigator.MoveToParent ();
}
if (navigator.MoveToFirstChild ()) {
do {
WriteNode (navigator, defattr);
} while (navigator.MoveToNext ());
navigator.MoveToParent ();
}
if (navigator.IsEmptyElement)
WriteEndElement ();
else
WriteFullEndElement ();
break;
default:
throw new NotSupportedException ();
}
}
示例7: Create
/// <summary>
/// Initialize the NamespaceIterator.
/// </summary>
public void Create(XPathNavigator context) {
// Push all of context's in-scope namespaces onto a stack in order to return them in document order
// (MoveToXXXNamespace methods return namespaces in reverse document order)
this.navStack.Reset();
if (context.MoveToFirstNamespace(XPathNamespaceScope.All)) {
do {
// Don't return the default namespace undeclaration
if (context.LocalName.Length != 0 || context.Value.Length != 0)
this.navStack.Push(context.Clone());
}
while (context.MoveToNextNamespace(XPathNamespaceScope.All));
context.MoveToParent();
}
}
示例8: ReadSubtreeNamespace
public void ReadSubtreeNamespace ()
{
string xml = "<root xmlns='urn:foo' />";
nav = GetXmlDocumentNavigator (xml);
nav.MoveToFirstChild ();
nav.MoveToFirstNamespace ();
nav.ReadSubtree ();
}
示例9: Compile
public CompiledStylesheet Compile (XPathNavigator nav, XmlResolver res, Evidence evidence)
{
this.xpathParser = new XPathParser (this);
this.patternParser = new XsltPatternParser (this);
this.res = res;
if (res == null)
this.res = new XmlUrlResolver ();
this.evidence = evidence;
// reject empty document.
if (nav.NodeType == XPathNodeType.Root && !nav.MoveToFirstChild ())
throw new XsltCompileException ("Stylesheet root element must be either \"stylesheet\" or \"transform\" or any literal element", null, nav);
while (nav.NodeType != XPathNodeType.Element) nav.MoveToNext();
stylesheetVersion = nav.GetAttribute ("version",
(nav.NamespaceURI != XsltNamespace) ?
XsltNamespace : String.Empty);
outputs [""] = new XslOutput ("", stylesheetVersion);
PushInputDocument (nav);
if (nav.MoveToFirstNamespace (XPathNamespaceScope.ExcludeXml))
{
do {
nsMgr.AddNamespace (nav.LocalName, nav.Value);
} while (nav.MoveToNextNamespace (XPathNamespaceScope.ExcludeXml));
nav.MoveToParent ();
}
try {
rootStyle = new XslStylesheet ();
rootStyle.Compile (this);
} catch (XsltCompileException) {
throw;
} catch (Exception x) {
throw new XsltCompileException ("XSLT compile error. " + x.Message, x, Input);
}
return new CompiledStylesheet (rootStyle, globalVariables, attrSets, nsMgr, keys, outputs, decimalFormats, msScripts);
}
示例10: CopyNode
void CopyNode (XslTransformProcessor p, XPathNavigator nav)
{
Outputter outputter = p.Out;
switch (nav.NodeType) {
case XPathNodeType.Root:
XPathNodeIterator itr = nav.SelectChildren (XPathNodeType.All);
while (itr.MoveNext ())
CopyNode (p, itr.Current);
break;
case XPathNodeType.Element:
bool isCData = p.InsideCDataElement;
string prefix = nav.Prefix;
string ns = nav.NamespaceURI;
p.PushElementState (prefix, nav.LocalName, ns, false);
outputter.WriteStartElement (prefix, nav.LocalName, ns);
if (nav.MoveToFirstNamespace (XPathNamespaceScope.ExcludeXml))
{
do {
if (prefix == nav.Name)
continue;
if (nav.Name.Length == 0 && ns.Length == 0)
continue;
outputter.WriteNamespaceDecl (nav.Name, nav.Value);
} while (nav.MoveToNextNamespace (XPathNamespaceScope.ExcludeXml));
nav.MoveToParent ();
}
if (nav.MoveToFirstAttribute())
{
do {
outputter.WriteAttributeString (nav.Prefix, nav.LocalName, nav.NamespaceURI, nav.Value);
} while (nav.MoveToNextAttribute ());
nav.MoveToParent();
}
if (nav.MoveToFirstChild ()) {
do {
CopyNode (p, nav);
} while (nav.MoveToNext ());
nav.MoveToParent ();
}
if (nav.IsEmptyElement)
outputter.WriteEndElement ();
else
outputter.WriteFullEndElement ();
p.PopCDataState (isCData);
break;
case XPathNodeType.Namespace:
if (nav.Name != p.XPathContext.ElementPrefix &&
(p.XPathContext.ElementNamespace.Length > 0 || nav.Name.Length > 0))
outputter.WriteNamespaceDecl (nav.Name, nav.Value);
break;
case XPathNodeType.Attribute:
outputter.WriteAttributeString (nav.Prefix, nav.LocalName, nav.NamespaceURI, nav.Value);
break;
case XPathNodeType.Whitespace:
case XPathNodeType.SignificantWhitespace:
bool cdata = outputter.InsideCDataSection;
outputter.InsideCDataSection = false;
outputter.WriteString (nav.Value);
outputter.InsideCDataSection = cdata;
break;
case XPathNodeType.Text:
outputter.WriteString (nav.Value);
break;
case XPathNodeType.ProcessingInstruction:
outputter.WriteProcessingInstruction (nav.Name, nav.Value);
break;
case XPathNodeType.Comment:
outputter.WriteComment (nav.Value);
break;
}
}
示例11: WriteNode
public virtual void WriteNode(XPathNavigator navigator, bool defattr)
{
bool flag;
if (navigator == null)
{
throw new ArgumentNullException("navigator");
}
int num = 0;
navigator = navigator.Clone();
Label_0018:
flag = false;
switch (navigator.NodeType)
{
case XPathNodeType.Root:
flag = true;
break;
case XPathNodeType.Element:
this.WriteStartElement(navigator.Prefix, navigator.LocalName, navigator.NamespaceURI);
if (navigator.MoveToFirstAttribute())
{
do
{
IXmlSchemaInfo schemaInfo = navigator.SchemaInfo;
if ((defattr || (schemaInfo == null)) || !schemaInfo.IsDefault)
{
this.WriteStartAttribute(navigator.Prefix, navigator.LocalName, navigator.NamespaceURI);
this.WriteString(navigator.Value);
this.WriteEndAttribute();
}
}
while (navigator.MoveToNextAttribute());
navigator.MoveToParent();
}
if (navigator.MoveToFirstNamespace(XPathNamespaceScope.Local))
{
this.WriteLocalNamespaces(navigator);
navigator.MoveToParent();
}
flag = true;
break;
case XPathNodeType.Text:
this.WriteString(navigator.Value);
break;
case XPathNodeType.SignificantWhitespace:
case XPathNodeType.Whitespace:
this.WriteWhitespace(navigator.Value);
break;
case XPathNodeType.ProcessingInstruction:
this.WriteProcessingInstruction(navigator.LocalName, navigator.Value);
break;
case XPathNodeType.Comment:
this.WriteComment(navigator.Value);
break;
}
if (flag)
{
if (navigator.MoveToFirstChild())
{
num++;
goto Label_0018;
}
if (navigator.NodeType == XPathNodeType.Element)
{
if (navigator.IsEmptyElement)
{
this.WriteEndElement();
}
else
{
this.WriteFullEndElement();
}
}
}
while (num != 0)
{
if (navigator.MoveToNext())
{
goto Label_0018;
}
num--;
navigator.MoveToParent();
if (navigator.NodeType == XPathNodeType.Element)
{
this.WriteFullEndElement();
}
}
}
示例12: ProcessElementNode
private void ProcessElementNode(XPathNavigator node, InternalFormContext ctx)
{
Debug.Assert(node.NodeType == XPathNodeType.Element);
log.Debug("Processing element node: {0} ({1})", node.Name, node.NamespaceURI);
if (IsPreprocessElement(node))
{
PreprocessElementNode(node, ctx);
}
else
{
ctx.Output.WriteStartElement(node.Prefix, node.LocalName, node.NamespaceURI);
if (node.MoveToFirstAttribute())
{
do
{
ctx.Output.WriteAttributeString(node.Prefix, node.LocalName, node.NamespaceURI, node.Value);
} while (node.MoveToNextAttribute());
node.MoveToParent();
}
if (!ctx.FirstElementHandled)
{
if (node.MoveToFirstNamespace())
{
do
{
log.Debug("Writing namespace declaration: {0}:{1}", node.LocalName, node.Value);
ctx.Output.WriteAttributeString("xmlns", node.LocalName, null, node.Value);
}
while (node.MoveToNextNamespace());
node.MoveToParent();
}
ctx.FirstElementHandled = true;
}
if (!node.IsEmptyElement)
{
VisitChildren(node, ctx);
}
ctx.Output.WriteEndElement();
log.Debug("End processing element node: {0} ({1})", node.Name, node.NamespaceURI);
}
}