本文整理汇总了C#中System.Xml.Linq.XNode类的典型用法代码示例。如果您正苦于以下问题:C# XNode类的具体用法?C# XNode怎么用?C# XNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XNode类属于System.Xml.Linq命名空间,在下文中一共展示了XNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Serialize
public void Serialize(TextWriter writer, XNode node, MediaRange mediaType)
{
var element = node is XDocument ? ((XDocument)node).Root : node as XElement;
if (element == null)
throw new InvalidOperationException();
// Each element node is visited in document order, except non-relevant elements are skipped if the relevant
// setting of the submission is true. Each visited element that has no child element nodes (i.e., each leaf
// element node) is selected for inclusion, including those that have no value (no text node). Note that
// attribute information is not preserved.
var separ = false;
var items = element
.DescendantsAndSelf()
.Where(i => !i.HasElements);
foreach (var item in items)
{
// write separator on subsequent nodes
if (separ)
writer.Write(';');
// encode values
writer.Write(Encode(item.Name.LocalName));
writer.Write('=');
writer.Write(Encode(item.Value));
separ = true;
}
}
示例2: MergeAdjacentInstrText
private static object MergeAdjacentInstrText(
XNode node)
{
XElement element = node as XElement;
if (element != null)
{
if (element.Name == W.r && element.Elements(W.instrText).Any())
{
var grouped = element.Elements().GroupAdjacent(e => e.Name == W.instrText);
return new XElement(W.r,
grouped.Select(g =>
{
if (g.Key == false)
return (object)g;
string newInstrText = g.Select(i => (string)i).StringConcatenate();
return new XElement(W.instrText,
newInstrText[0] == ' ' || newInstrText[newInstrText.Length - 1] == ' ' ?
new XAttribute(XNamespace.Xml + "space", "preserve") : null,
newInstrText);
}));
}
return new XElement(element.Name,
element.Attributes(),
element.Nodes()
.Select(n =>
MergeAdjacentInstrText(n)));
}
return node;
}
示例3: XNodeReader
internal XNodeReader(XNode node, XmlNameTable nameTable, ReaderOptions options)
{
_source = node;
_root = node;
_nameTable = nameTable != null ? nameTable : CreateNameTable();
_omitDuplicateNamespaces = (options & ReaderOptions.OmitDuplicateNamespaces) != 0 ? true : false;
}
示例4: Serialize
public void Serialize(TextWriter writer, XNode node, MediaRange mediaType)
{
Contract.Requires<ArgumentNullException>(node != null);
Contract.Requires<ArgumentNullException>(writer != null);
Contract.Requires<ArgumentNullException>(mediaType != null);
throw new System.NotImplementedException();
}
示例5: Process
public override IEnumerable< XNode > Process(XNode node)
{
XElement element = _AssumeElement( node );
string symbol_name = element.Name.LocalName;
if ( !_Env.IsDefined( symbol_name ) )
throw InvalidMarkupException.CreateException( "[{0}] Undefined symbol '{1}' ",
node.ErrorContext(),
element.Name );
/* Evaluate the symbol on a new stack frame, since we may be defining local symbols
* based on the attributes */
return _Env.Call( () =>
{
/* Bind attributes as local symbolic definitions */
_DefineFromAttributes( element );
/* Bind any nested definition elements */
_ProcessNodes(
element.Elements( _Env._Settings.Namespace.GetName("define") ).Select
( n => ( XNode ) n ) );
// Must materialize the deferred-execution nodeset
// iterator before this method returns, otherwise
// the evaluation stack will be wrong. Calling ToArray()
// ensures this.
return _Env.EvalSymbol( symbol_name ).ToArray();
//return _ProcessNodes( ret );
} );
}
示例6: ConvertHtmlEntityToXaml
public XNode ConvertHtmlEntityToXaml(XNode node)
{
if (node is XText)
{
return node;
}
var element = node as XElement;
if (element == null)
{
return null;
}
string tagName = element.Name.LocalName;
if (tagName == "br")
{
return new XElement("LineBreak");
}
if (this._tagsToFunctionsMap.ContainsKey(tagName))
{
var innerXaml = this.ConvertHtmlEntitiesToXaml(element.Nodes());
var result = this._tagsToFunctionsMap[tagName](element, innerXaml);
return result;
}
return new XText(element.Value);
}
示例7: addNodes
private void addNodes(XNode root, TreeNode treeRoot)
{
TreeNode t;
if (root.NodeType != XmlNodeType.Element)
return;
XElement e = root as XElement;
switch (e.Name.LocalName)
{
case "topic":
treeRoot.Text = e.Attributes().Where(attrib => attrib.Name.LocalName == "title").First().Value;
if (e.Attributes().Where(attrib => attrib.Name.LocalName == "filename").Count() > 0)
treeRoot.Tag = GetTextFile(e.Attributes().Where(attrib => attrib.Name.LocalName == "filename").First().Value);
/*temp = .First().Value;
if (temp != null && temp != "")
treeRoot.Tag = temp;*/
foreach (XElement item in e.Nodes())
{
t = new TreeNode();
treeRoot.Nodes.Add(t);
addNodes(item, t);
}
break;
case "section":
treeRoot.Text = e.Attributes().Where(attrib => attrib.Name.LocalName == "title").First().Value;
treeRoot.Tag = GetTextFile(e.Attributes().Where(attrib => attrib.Name.LocalName == "filename").First().Value);
break;
}
//if (root.Name.LocalName
}
示例8: IsOSSIndexIgnored
private bool IsOSSIndexIgnored(XNode node)
{
if (node == null || node.PreviousNode == null)
{
return false;
}
switch (node.PreviousNode.NodeType)
{
case XmlNodeType.Whitespace:
case XmlNodeType.Text:
case XmlNodeType.None:
{
return IsOSSIndexIgnored(node.PreviousNode);
}
case XmlNodeType.Comment:
{
var commentValue = (node.PreviousNode as XComment).Value;
if (commentValue.Replace(" ", string.Empty).Contains("@OSSIndexIgnore"))
{
return true;
}
return IsOSSIndexIgnored(node.PreviousNode);
}
default:
{
return false;
}
}
}
示例9: TryMakeXEmbedable
// IFunctionResultToXElementMapper
public bool TryMakeXEmbedable(FunctionContextContainer contextContainer, object resultObject, out XNode resultElement)
{
var control = resultObject as Control;
if (control == null)
{
resultElement = null;
return false;
}
string controlMarkerKey;
lock (_controls)
{
controlMarkerKey = string.Format("[Composite.Function.Render.Asp.Net.Control.{0}]", _controls.Count);
_controls.Add(controlMarkerKey, control);
}
resultElement =
XElement.Parse(@"<c1marker:{0} xmlns:c1marker=""{1}"" key=""{2}"" />"
.FormatWith(_markerElementName.LocalName,
_markerElementName.Namespace,
controlMarkerKey));
return true;
}
示例10: _ProcessIteration
private IEnumerable< XNode > _ProcessIteration(XElement element, XNode iterVal,
string iterName)
{
XNode val = iterVal;
IEnumerable< XNode > results = _Env.Call( () =>
{
/* Bind the iterator symbolic name to the current value */
if ( val is XContainer )
/* Nodeset value */
{
_Env.DefineNodesetSymbol(
iterName,
( ( XContainer ) val ).
Nodes() );
}
else /* Text value */
{
_Env.DefineTextSymbol( iterName,
val.
ToString
() );
}
/* Process loop body */
return _ProcessNodes( element.Nodes() );
} );
return results;
}
示例11: XNodeReader
internal XNodeReader(XNode node, XmlNameTable nameTable, ReaderOptions options)
{
this.source = node;
this.root = node;
this.nameTable = (nameTable != null) ? nameTable : CreateNameTable();
this.omitDuplicateNamespaces = (options & ReaderOptions.OmitDuplicateNamespaces) != ReaderOptions.None;
}
示例12: Process
public override IEnumerable< XNode > Process(XNode node)
{
try
{
//Console.WriteLine("Processing {0}", node.ErrorContext());
switch ( node.NodeType )
{
case XmlNodeType.Element:
return _ProcessElement( ( XElement ) node );
/* PI,CDATA nodes are copied as-is */
case XmlNodeType.ProcessingInstruction:
return new[] {new XProcessingInstruction( ( XProcessingInstruction ) node )};
case XmlNodeType.CDATA:
return new[] {new XCData( ( XCData ) node )};
case XmlNodeType.Text:
return _ProcessTextNode( ( XText ) node );
case XmlNodeType.Comment:
return new[] {new XComment( ( XComment ) node )};
case XmlNodeType.DocumentType:
case XmlNodeType.Entity:
case XmlNodeType.EntityReference:
return new[] { node };
default:
throw new InvalidOperationException( "Unhandled Xml Node Type: " +
node.NodeType );
}
}
catch ( PreprocessorException )
{
throw;
}
}
示例13: CreateXDocumentMixNoArrayConnected
// XDocument
// - from node without parent, from nodes with parent
// - allowed types
// - attributes
// - Document
// - doubled decl, root elem, doctype
// - the same valid object instance multiple times
// - array/IEnumerable of allowed types
// - array/IEnumerable including not allowed types
//[Variation(Priority = 0, Desc = "XDocument - adding element", Param = "XElement")]
//[Variation(Priority = 1, Desc = "XDocument - adding PI", Param = "XPI")]
//[Variation(Priority = 1, Desc = "XDocument - adding XmlDecl", Param = "XmlDecl")]
//[Variation (Priority=1, Desc="XDocument - adding dot type")]
//[Variation(Priority = 1, Desc = "XDocument - adding Comment", Param = "XComment")]
//[Variation(Priority = 1, Desc = "XDocument - combination off allowed types in correct order", Param = "Mix1")]
//[Variation(Priority = 1, Desc = "XDocument - combination off allowed types in correct order, without decl", Param = "Mix2")]
//[Variation(Priority = 2, Desc = "XDocument - adding string/whitespace", Param = "Whitespace")]
public void CreateXDocumentMixNoArrayConnected()
{
var doc1 = new XDocument(new XProcessingInstruction("PI", "data"), new XComment("comm1"), new XElement("root", new XAttribute("id", "a1")), new XComment("comm2"));
var nodes = new XNode[4];
XNode nn = doc1.FirstNode;
for (int i = 0; i < nodes.Length; i++)
{
nodes[i] = nn;
nn = nn.NextNode;
}
var doc = new XDocument(nodes[0], nodes[1], nodes[2], nodes[3]);
int nodeCounter = 0;
for (XNode n = doc.FirstNode; n != null; n = n.NextNode)
{
TestLog.Compare(n != nodes[nodeCounter], "identity");
TestLog.Compare(XNode.DeepEquals(n, nodes[nodeCounter]), "Equals");
TestLog.Compare(nodes[nodeCounter].Document == doc1, "orig Document");
TestLog.Compare(n.Document == doc, "new Document");
nodeCounter++;
}
TestLog.Compare(nodeCounter, nodes.Length, "All nodes added");
}
示例14: RuntimeOrderPipelinesProcessorConfiguration
public RuntimeOrderPipelinesProcessorConfiguration(XNode xml)
{
if (xml == null) throw new ArgumentNullException("xml");
using (var r = xml.CreateReader())
{
base.DeserializeElement(r, false);
}
}
开发者ID:enticify,项目名称:Enticify.Cs2009.Components,代码行数:8,代码来源:RuntimeOrderPipelinesProcessorConfiguration.cs
示例15: Process
public override IEnumerable< XNode > Process(XNode node)
{
XElement element = _AssumeElement( node );
Validation.RequireAttributes( element, AttrName.Name );
var name = ( string ) element.Attribute( AttrName.Name );
bool defined = _TestCondition( name );
return _ProcessConditional( element, defined );
}