本文整理汇总了C#中MonoDevelop.XmlEditor.XmlElementPath.Compact方法的典型用法代码示例。如果您正苦于以下问题:C# XmlElementPath.Compact方法的具体用法?C# XmlElementPath.Compact怎么用?C# XmlElementPath.Compact使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MonoDevelop.XmlEditor.XmlElementPath
的用法示例。
在下文中一共展示了XmlElementPath.Compact方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetActiveElementStartPath
/// <summary>
/// Gets path of the xml element start tag that the specified
/// <paramref name="index"/> is currently inside.
/// </summary>
/// <remarks>If the index outside the start tag then an empty path
/// is returned.</remarks>
public static XmlElementPath GetActiveElementStartPath(string xml, int index)
{
XmlElementPath path = new XmlElementPath();
string elementText = GetActiveElementStartText(xml, index);
if (elementText != null) {
QualifiedName elementName = GetElementName(elementText);
NamespaceURI elementNamespace = GetElementNamespace(elementText);
path = GetParentElementPath(xml.Substring(0, index));
if (elementNamespace.Namespace.Length == 0) {
if (path.Elements.Count > 0) {
QualifiedName parentName = path.Elements[path.Elements.Count - 1];
elementNamespace.Namespace = parentName.Namespace;
elementNamespace.Prefix = parentName.Prefix;
}
}
path.Elements.Add(new QualifiedName(elementName.Name, elementNamespace.Namespace, elementNamespace.Prefix));
path.Compact();
}
return path;
}
示例2: GetParentElementPath
/// <summary>
/// Gets the parent element path based on the index position.
/// </summary>
public static XmlElementPath GetParentElementPath(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);
}
break;
case XmlNodeType.EndElement:
path.Elements.RemoveLast();
break;
}
}
} catch (XmlException) {
// Do nothing.
} catch (WebException) {
// Do nothing.
}
path.Compact();
return path;
}