本文整理汇总了C#中System.Xml.XmlDocument.ReadNode方法的典型用法代码示例。如果您正苦于以下问题:C# XmlDocument.ReadNode方法的具体用法?C# XmlDocument.ReadNode怎么用?C# XmlDocument.ReadNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlDocument
的用法示例。
在下文中一共展示了XmlDocument.ReadNode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadNodes
public static XmlNode[] ReadNodes(XmlReader xmlReader)
{
if (xmlReader == null)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("xmlReader");
XmlDocument doc = new XmlDocument();
List<XmlNode> nodeList = new List<XmlNode>();
if (xmlReader.MoveToFirstAttribute())
{
do
{
if (IsValidAttribute(xmlReader))
{
XmlNode node = doc.ReadNode(xmlReader);
if (node == null)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.GetString(SR.UnexpectedEndOfFile)));
nodeList.Add(node);
}
} while (xmlReader.MoveToNextAttribute());
}
xmlReader.MoveToElement();
if (!xmlReader.IsEmptyElement)
{
int startDepth = xmlReader.Depth;
xmlReader.Read();
while (xmlReader.Depth > startDepth && xmlReader.NodeType != XmlNodeType.EndElement)
{
XmlNode node = doc.ReadNode(xmlReader);
if (node == null)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.GetString(SR.UnexpectedEndOfFile)));
nodeList.Add(node);
}
}
return nodeList.ToArray();
}
示例2: ExecuteTask
protected override void ExecuteTask()
{
string filename = XmlFile.FullName;
Log(Level.Info, "Attempting to load XML document in file '{0}'.", filename );
XmlDocument document = new XmlDocument();
document.Load(filename);
Log(Level.Info, "XML document in file '{0}' loaded successfully.", filename );
XmlNodeList nodes = document.SelectNodes(XPath);
if(null == nodes)
{
throw new BuildException(String.Format("Node not found by XPath '{0}'", XPath));
}
for (Int32 i = 0, c = nodes.Count, last = c - 1; i < c; i++)
{
XmlNode node = nodes[i];
if (i == last && NewXml != null)
{
Log(Level.Info, "Replacing last node with new XML: {0}", NewXml);
XmlNode newnode = document.ReadNode(new XmlTextReader(new StringReader(NewXml)));
node.ParentNode.ReplaceChild(newnode, node);
}
else
{
node.ParentNode.RemoveChild(node);
}
}
// if (null != NewNode) node.ParentNode.AppendChild(NewNode);
Log(Level.Info, "Attempting to save XML document to '{0}'.", filename );
document.Save(filename);
Log(Level.Info, "XML document successfully saved to '{0}'.", filename );
}
示例3: GetXmlRootNode
public static XmlNode GetXmlRootNode(String fileName, String nodeName)
{
XmlDocument doc = new XmlDocument();
XmlTextReader textReader = new XmlTextReader(fileName);
XmlNode currNode = doc.ReadNode(textReader);
while (currNode != null)
{
if (currNode.NodeType == XmlNodeType.Element)
{
if (currNode.Name.Equals(nodeName, StringComparison.OrdinalIgnoreCase))
return currNode;
}
currNode = doc.ReadNode(textReader);
}
return null;
}
示例4: DeleteWritingSystemId
public void DeleteWritingSystemId(string id)
{
var fileToBeWrittenTo = new TempFile();
var reader = XmlReader.Create(_liftFilePath, CanonicalXmlSettings.CreateXmlReaderSettings());
var writer = XmlWriter.Create(fileToBeWrittenTo.Path, CanonicalXmlSettings.CreateXmlWriterSettings());
//System.Diagnostics.Process.Start(fileToBeWrittenTo.Path);
try
{
bool readerMovedByXmlDocument = false;
while (readerMovedByXmlDocument || reader.Read())
{
readerMovedByXmlDocument = false;
var xmldoc = new XmlDocument();
if (reader.NodeType == XmlNodeType.Element && reader.Name == "entry")
{
var entryFragment = xmldoc.ReadNode(reader);
readerMovedByXmlDocument = true;
var nodesWithLangId = entryFragment.SelectNodes(String.Format("//*[@lang='{0}']", id));
if (nodesWithLangId != null)
{
foreach (XmlNode node in nodesWithLangId)
{
var parent = node.SelectSingleNode("parent::*");
if (node.Name == "gloss")
{
parent.RemoveChild(node);
}
else
{
var siblingNodes =
node.SelectNodes("following-sibling::form | preceding-sibling::form");
if (siblingNodes.Count == 0)
{
var grandParent = parent.SelectSingleNode("parent::*");
grandParent.RemoveChild(parent);
}
else
{
parent.RemoveChild(node);
}
}
}
}
entryFragment.WriteTo(writer);
}
else
{
writer.WriteNodeShallow(reader);
}
//writer.Flush();
}
}
finally
{
reader.Close();
writer.Close();
}
File.Delete(_liftFilePath);
fileToBeWrittenTo.MoveTo(_liftFilePath);
}
示例5: ExtractData
public void ExtractData(string soapBody)
{
if (soapBody != String.Empty)
{
try
{
XmlTextReader xtr = new XmlTextReader(new System.IO.StringReader(soapBody));
XmlDocument doc = new XmlDocument();
XmlNode node = doc.ReadNode(xtr);
while (xtr.Read())
{
if (xtr.IsStartElement())
{
// Get element name
switch (xtr.Name)
{
//extract session id
case "SessionId":
if (xtr.Read())
{
sessionID = xtr.Value.Trim();
}
break;
//extract object's name
case "sObject":
if (xtr["xsi:type"] != null)
{
string sObjectName = xtr["xsi:type"];
if (sObjectName != null)
{
objectName = sObjectName.Split(new char[] { ':' })[1];
}
}
break;
//extract notification id [note: salesforce can send a notification multiple times. it is, therefore, a good idea to keep track of this id.]
case "Id":
if (xtr.Read())
{
notificationIDs.Add(xtr.Value.Trim());
}
break;
//extract record id
case "sf:Id":
if (xtr.Read())
{
objectIDs.Add(xtr.Value.Trim());
}
break;
}
}
}
}
catch (Exception)
{
//TODO: log exception
}
}
}
示例6: Main
/// ------------------------------------------------------------------------------------
/// <summary>
/// The main entry point
/// </summary>
/// ------------------------------------------------------------------------------------
static void Main(string[] args)
{
if (args.Length < 1)
{
Console.WriteLine("Creates manifest files so that exe can be run without COM " +
"needed to be registered in the registry.");
Console.WriteLine();
Console.WriteLine("Usage:");
Console.WriteLine("regfreeApp <exename>");
return;
}
string executable = args[0];
if (!File.Exists(executable))
{
Console.WriteLine("File {0} does not exist", executable);
return;
}
string manifestFile = executable + ".manifest";
XmlDocument doc = new XmlDocument();
doc.PreserveWhitespace = true;
if (File.Exists(manifestFile))
{
using (XmlReader reader = new XmlTextReader(manifestFile))
{
try
{
reader.MoveToContent();
}
catch (XmlException)
{
}
doc.ReadNode(reader);
}
}
RegFreeCreator creator = new RegFreeCreator(doc, false);
XmlElement root = creator.CreateExeInfo(executable);
string directory = Path.GetDirectoryName(executable);
if (directory.Length == 0)
directory = Directory.GetCurrentDirectory();
foreach (string fileName in Directory.GetFiles(directory, "*.dll"))
creator.ProcessTypeLibrary(root, fileName);
XmlWriterSettings settings = new XmlWriterSettings();
settings.OmitXmlDeclaration = false;
settings.NewLineOnAttributes = false;
settings.NewLineChars = Environment.NewLine;
settings.Indent = true;
settings.IndentChars = "\t";
using (XmlWriter writer = XmlWriter.Create(manifestFile, settings))
{
doc.WriteContentTo(writer);
}
}
示例7: DeserializeElementForDocument
protected virtual XmlElement DeserializeElementForDocument(XmlDocument ownerDocument, Stream source)
{
using (var xmlReader = XmlReader.Create(source))
{
var element = (XmlElement)ownerDocument.ReadNode(xmlReader);
var elementForDoc = (XmlElement)ownerDocument.ImportNode(element, true);
return elementForDoc;
}
}
示例8: TryProcessFeedStream
private bool TryProcessFeedStream(BufferingStreamReader responseStream)
{
bool isRssOrFeed = false;
try
{
XmlReaderSettings readerSettings = GetSecureXmlReaderSettings();
XmlReader reader = XmlReader.Create(responseStream, readerSettings);
// See if the reader contained an "RSS" or "Feed" in the first 10 elements (RSS and Feed are normally 2 or 3)
int readCount = 0;
while ((readCount < 10) && reader.Read())
{
if (String.Equals("rss", reader.Name, StringComparison.OrdinalIgnoreCase) ||
String.Equals("feed", reader.Name, StringComparison.OrdinalIgnoreCase))
{
isRssOrFeed = true;
break;
}
readCount++;
}
if (isRssOrFeed)
{
XmlDocument workingDocument = new XmlDocument();
// performing a Read() here to avoid rrechecking
// "rss" or "feed" items
reader.Read();
while (!reader.EOF)
{
// If node is Element and it's the 'Item' or 'Entry' node, emit that node.
if ((reader.NodeType == XmlNodeType.Element) &&
(string.Equals("Item", reader.Name, StringComparison.OrdinalIgnoreCase) ||
string.Equals("Entry", reader.Name, StringComparison.OrdinalIgnoreCase))
)
{
// this one will do reader.Read() internally
XmlNode result = workingDocument.ReadNode(reader);
WriteObject(result);
}
else
{
reader.Read();
}
}
}
}
catch (XmlException) { }
finally
{
responseStream.Seek(0, SeekOrigin.Begin);
}
return isRssOrFeed;
}
示例9: ReadDataSourceExtraInformation
internal void ReadDataSourceExtraInformation(XmlTextReader xmlTextReader)
{
XmlDocument document = new XmlDocument();
XmlNode newChild = document.ReadNode(xmlTextReader);
document.AppendChild(newChild);
if (this.serializer != null)
{
this.serializer.DeserializeBody((XmlElement) newChild, this);
}
}
示例10: DownCastToSurfaceElement
private static XmlElement DownCastToSurfaceElement(XElement element)
{
XNamespace ns = "http://www.opengis.net/gml/3.2";
XmlDocument doc = new XmlDocument();
element.Name = ns+ "Surface";
return doc.ReadNode(element.CreateReader()) as XmlElement;
}
示例11: ArrangeTransformElement
private XmlElement ArrangeTransformElement(XmlDocument document, string xml)
{
using (var textReader = new StringReader(xml))
{
using (var xmlReader = new XmlTextReader(textReader))
{
var node = document.ReadNode(xmlReader);
return (XmlElement)node;
}
}
}
示例12: ReadNodes
public static System.Xml.XmlNode[] ReadNodes(XmlReader xmlReader)
{
if (xmlReader == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("xmlReader");
}
XmlDocument document = new XmlDocument();
List<System.Xml.XmlNode> list = new List<System.Xml.XmlNode>();
if (xmlReader.MoveToFirstAttribute())
{
do
{
if (IsValidAttribute(xmlReader))
{
System.Xml.XmlNode item = document.ReadNode(xmlReader);
if (item == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(System.Runtime.Serialization.SR.GetString("UnexpectedEndOfFile")));
}
list.Add(item);
}
}
while (xmlReader.MoveToNextAttribute());
}
xmlReader.MoveToElement();
if (!xmlReader.IsEmptyElement)
{
int depth = xmlReader.Depth;
xmlReader.Read();
while ((xmlReader.Depth > depth) && (xmlReader.NodeType != XmlNodeType.EndElement))
{
System.Xml.XmlNode node2 = document.ReadNode(xmlReader);
if (node2 == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(System.Runtime.Serialization.SR.GetString("UnexpectedEndOfFile")));
}
list.Add(node2);
}
}
return list.ToArray();
}
示例13: OperationForBodyA
public Message OperationForBodyA(Message msg)
{
// create reply for this operation, wrapping the original request body
XmlDocument responseBody = new XmlDocument();
responseBody.AppendChild(responseBody.CreateElement("replyBodyA", "http://tempuri.org"));
responseBody.DocumentElement.AppendChild(responseBody.ReadNode(msg.GetReaderAtBodyContents()));
Message reply = Message.CreateMessage(
msg.Version,
null,
new XmlNodeReader(responseBody.DocumentElement));
return reply;
}
示例14: Load
public static bool Load(XmlTextReader reader, Report report)
{
var xmlDoc = new XmlDocument();
XmlNode el;
while ((el = xmlDoc.ReadNode(reader)) != null)
{
if (el.NodeType != XmlNodeType.Element)
continue;
Load((XmlElement)el, report);
return true;
}
return false;
}
示例15: ParseConstraintString
/// <summary>
/// Parse the constraint string to set the class properties.
/// </summary>
public override void ParseConstraintString()
{
XmlTextReader node = new XmlTextReader(ConstraintString,XmlNodeType.Element,null);
XmlDocument doc = new XmlDocument();
XmlNode xmlConstraint = doc.ReadNode(node);
base.Name = xmlConstraint.Attributes["name"].Value;
base.Property = xmlConstraint.Attributes["property"].Value;
base.Operator = (ConstraintOperator)Enum.Parse(typeof(Klod.Validation.ConstraintOperator),xmlConstraint.Attributes["operator"].Value);
base.TypeToValidate = Type.GetType(xmlConstraint.Attributes["typeToValidate"].Value);
base.Value = xmlConstraint.Attributes["value"].Value;
base.ValueType = Type.GetType(xmlConstraint.Attributes["valueType"].Value);
}