本文整理匯總了C#中System.Xml.XmlTextReader.GetNamespacesInScope方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlTextReader.GetNamespacesInScope方法的具體用法?C# XmlTextReader.GetNamespacesInScope怎麽用?C# XmlTextReader.GetNamespacesInScope使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.XmlTextReader
的用法示例。
在下文中一共展示了XmlTextReader.GetNamespacesInScope方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: GetFullParentElementPath
/// <summary>
/// Gets the parent element path based on the index position. This
/// method does not compact the path so it will include all elements
/// including those in another namespace in the path.
/// </summary>
static XmlElementPath GetFullParentElementPath(string xml)
{
XmlElementPath path = new XmlElementPath();
IDictionary<string, string> namespacesInScope = null;
using (StringReader reader = new StringReader(xml)) {
using (XmlTextReader xmlReader = new XmlTextReader(reader)) {
try {
xmlReader.XmlResolver = null; // prevent XmlTextReader from loading external DTDs
while (xmlReader.Read()) {
switch (xmlReader.NodeType) {
case XmlNodeType.Element:
if (!xmlReader.IsEmptyElement) {
QualifiedName elementName = new QualifiedName(xmlReader.LocalName, xmlReader.NamespaceURI, xmlReader.Prefix);
path.AddElement(elementName);
}
break;
case XmlNodeType.EndElement:
path.Elements.RemoveLast();
break;
}
}
} catch (XmlException) {
namespacesInScope = xmlReader.GetNamespacesInScope(XmlNamespaceScope.All);
}
}
}
// Add namespaces in scope for the last element read.
if (namespacesInScope != null) {
foreach (KeyValuePair<string, string> ns in namespacesInScope) {
path.NamespacesInScope.Add(new XmlNamespace(ns.Key, ns.Value));
}
}
return path;
}
示例2: GetParentElementPathCore
public static XmlElementPath GetParentElementPathCore(string xml)
{
XmlElementPath path = new XmlElementPath();
try
{
StringReader reader = new StringReader(xml);
XmlTextReader xmlReader = new XmlTextReader(reader);
xmlReader.XmlResolver = null;
while (xmlReader.Read())
{
switch (xmlReader.NodeType)
{
case XmlNodeType.Element:
if (!xmlReader.IsEmptyElement)
{
QualifiedName elementName = new QualifiedName(xmlReader.LocalName, xmlReader.NamespaceURI, xmlReader.Prefix);
path.Elements.Add(elementName);
path.Namespaces = xmlReader.GetNamespacesInScope(XmlNamespaceScope.All);
}
break;
case XmlNodeType.EndElement:
path.Elements.RemoveLast();
break;
}
}
}
catch (XmlException)
{
// Do nothing.
}
catch (WebException)
{
// Do nothing.
}
return path;
}
示例3: CheckIfNameSpaceDAVSpace
/// <summary>
/// This method checks if the attached
/// </summary>
/// <param name="element"></param>
/// <param name="reader"></param>
/// <returns></returns>
private static bool CheckIfNameSpaceDAVSpace(String element, XmlTextReader reader)
{
// split the element into tag and field
String[] fields = element.Split(':');
// could be that the element has no namespace attached, so it is not part
// of the webdav response
if (fields.Length == 1)
return false;
// get the namespace list
IDictionary<String, String> nameSpaceList = reader.GetNamespacesInScope(XmlNamespaceScope.All);
// get the namespace of our node
if (!nameSpaceList.ContainsKey(fields[0]))
return false;
// get the value
String NsValue = nameSpaceList[fields[0]];
// compare if it's a DAV namespce
if (NsValue.ToLower().Equals("dav:"))
return true;
else
return false;
}
示例4: GetNamespacesInScope
public static IDictionary<string, string> GetNamespacesInScope(string xml)
{
try
{
var xmlReader = new XmlTextReader(new StringReader(xml));
xmlReader.XmlResolver = null;
while (xmlReader.Read())
{
switch (xmlReader.NodeType)
{
case XmlNodeType.Element:
return xmlReader.GetNamespacesInScope(XmlNamespaceScope.All);
}
}
}
catch (XmlException) { /* Do nothing. */ }
catch (WebException) { /* Do nothing. */ }
return null;
}