本文整理汇总了C#中System.Xml.XPath.XPathNavigator.MoveToAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# XPathNavigator.MoveToAttribute方法的具体用法?C# XPathNavigator.MoveToAttribute怎么用?C# XPathNavigator.MoveToAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XPath.XPathNavigator
的用法示例。
在下文中一共展示了XPathNavigator.MoveToAttribute方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetOrCreateXmlAttribute
public static void SetOrCreateXmlAttribute(XPathNavigator node, string localName, string namespaceURI, string value)
{
if (node.MoveToAttribute(localName, namespaceURI))
{
node.SetValue(value);
node.MoveToParent();
}
else
{
node.CreateAttribute("", localName, namespaceURI, value);
}
}
示例2: CreateAttribute
public XPathNavigator CreateAttribute(string name, string namespaceUri, XPathNavigator source)
{
source.CreateAttribute(null, name, namespaceUri, "");
source.MoveToAttribute(name, namespaceUri ?? "");
return source;
}
示例3: XmlElementWithAttributes
private void XmlElementWithAttributes (XPathNavigator nav)
{
nav.MoveToFirstChild ();
AssertNavigator ("#1", nav, XPathNodeType.Element, "", "img", "", "img", "", true, false, true);
Assert.IsTrue (!nav.MoveToNext ());
Assert.IsTrue (!nav.MoveToPrevious ());
Assert.IsTrue (nav.MoveToFirstAttribute ());
AssertNavigator ("#2", nav, XPathNodeType.Attribute, "", "src", "", "src", "foo.png", false, false, false);
Assert.IsTrue (!nav.MoveToFirstAttribute ()); // On attributes, it fails.
Assert.IsTrue (nav.MoveToNextAttribute ());
AssertNavigator ("#3", nav, XPathNodeType.Attribute, "", "alt", "", "alt", "image Fooooooo!", false, false, false);
Assert.IsTrue (!nav.MoveToNextAttribute ());
Assert.IsTrue (nav.MoveToParent ());
AssertNavigator ("#4", nav, XPathNodeType.Element, "", "img", "", "img", "", true, false, true);
Assert.IsTrue (nav.MoveToAttribute ("alt", ""));
AssertNavigator ("#5", nav, XPathNodeType.Attribute, "", "alt", "", "alt", "image Fooooooo!", false, false, false);
Assert.IsTrue (!nav.MoveToAttribute ("src", "")); // On attributes, it fails.
Assert.IsTrue (nav.MoveToParent ());
Assert.IsTrue (nav.MoveToAttribute ("src", ""));
AssertNavigator ("#6", nav, XPathNodeType.Attribute, "", "src", "", "src", "foo.png", false, false, false);
nav.MoveToRoot ();
AssertNavigator ("#7", nav, XPathNodeType.Root, "", "", "", "", "", false, true, false);
}
示例4: AnalyzeNodeChildren
/// <summary>
/// Function analyzes children of the node recursively
/// </summary>
/// <param name="nodeNavigator">current node whose children schould be analyzed</param>
/// <param name="groupName">currently created sequence of group names to this node</param>
/// <param name="parameterName">name of the compared parameter</param>
/// <param name="dictionaryEntry">entry for currently analyzed xml doc</param>
/// <param name="temp">temporary entry for the parameter to be filled</param>
public void AnalyzeNodeChildren(XPathNavigator nodeNavigator, string groupName, string parameterName, KeyValuePair<string, XPathDocument> dictionaryEntry, Dictionary<ParameterID, Dictionary<String, object>> temp)
{
nodeNavigator.MoveToFirstChild();
do
{
//----comparing param's attributes-----------------
if (nodeNavigator.HasChildren)
{
// This is a group
StringBuilder groupNameNewSB = new StringBuilder();
nodeNavigator.MoveToAttribute("NAME", "");
groupNameNewSB.Append(groupName);
if (groupName != "")
{
groupNameNewSB.Append(".");
}
groupNameNewSB.Append(nodeNavigator.Value);
nodeNavigator.MoveToParent();
AnalyzeNodeChildren(nodeNavigator, groupNameNewSB.ToString(), parameterName, dictionaryEntry, temp);
}
else
{
nodeNavigator.MoveToFirstAttribute();
do
{
switch (nodeNavigator.Name)
{
case "NAME":
break;
case "HINT":
break;
case "TYPE":
break;
case "VALUE": // this can be done better....... but anyways , let's continue :)
//paramValue = Convert.ToDouble(thisNavigator.ValueAsDouble);
object paramValue = null;
double doubleValue;
bool paramIsString = false;
if (!Double.TryParse(nodeNavigator.Value, NumberStyles.Number, CultureInfo.InvariantCulture/*CultureInfo.CreateSpecificCulture("en-GB")*/, out doubleValue))
{
paramValue = nodeNavigator.Value;
paramIsString = true;
}
//------- move to attribute doesn't work backwards (no idea why)
// update: because it cannot go from attribute to attribute with the use of
//MoveToAttribute method (in this case only MoveToNextAttribute can be used)
nodeNavigator.MoveToParent();
nodeNavigator.MoveToFirstChild();
nodeNavigator.MoveToAttribute("NAME", "");
//if no match with desired name 'break;' and go to the next one
if (!nodeNavigator.Value.Contains(parameterName))
{
nodeNavigator.MoveToParent();
nodeNavigator.MoveToFirstChild();
nodeNavigator.MoveToAttribute("VALUE", "");
break;
}
#region Adding parameter to temp
//....add( (fileName, Concatenated String <groupName + , + parameterName>), parameterValue)
if (paramIsString)
{
// For this I could have written a function :)
Dictionary<string, object> tempDictionary = new Dictionary<string, object>();
///if this parameter entry already exists, then only add it's difference entry in its dictionary
if (temp.TryGetValue(new ParameterID(nodeNavigator.Value, groupName, true), out tempDictionary))
//if (temp.ContainsKey(new parameterID(thisNavigator.Value, groupName)))
{
tempDictionary.Add(dictionaryEntry.Key, paramValue);
}
else
{
tempDictionary = new Dictionary<string, object>();
tempDictionary.Add(dictionaryEntry.Key, paramValue);
temp.Add(new ParameterID(nodeNavigator.Value, groupName, true), tempDictionary);
//(DictionaryEntry.Key, groupName + ", " + thisNavigator.Value), paramValue);
}
}
else
{
Dictionary<string, object> tempDictionary = new Dictionary<string, object>();
///if this parameter entry already exists, then only add it's difference entry in its dictionary
//.........这里部分代码省略.........
示例5: CreateAttribute
public XPathNavigator CreateAttribute(string name, string namespaceUri, XPathNavigator source)
{
name = XmlConvert.EncodeLocalName(name);
source.CreateAttribute(null, name, namespaceUri, "");
source.MoveToAttribute(name, namespaceUri ?? "");
return source;
}
示例6: createSubplatform
private void createSubplatform(XPathNavigator navLocal, XmlDocument document, XPathNavigator navGlobal)
{
//itSubplatforms.Current.CreateAttribute(String.Empty, "name", String.Empty, cName + "Subplatform" + subplatNum++ + AME.Tools.ImportTool.Delimitter + "Subplatform");
String eventName = navLocal.SelectSingleNode("parent::node()").GetAttribute("name", navLocal.NamespaceURI);
// Set up component values
String cType = "Subplatform";
String cName;
String cDescription = String.Empty;
// Create links
#region links
// SubplatformKind
String kind = (navLocal.SelectSingleNode("Kind") == null) ? String.Empty : navLocal.SelectSingleNode("Kind").Value;
kind = kind.Trim();
if (navGlobal.SelectSingleNode(String.Format("/Scenario/Species[Name='{0}']", kind)) != null)
{
// Create component _ Want Kind in the component name.
cName = navLocal.GetAttribute("name", navLocal.NamespaceURI) + AME.Tools.ImportTool.Delimitter + kind + "_" + cType;
navLocal.MoveToAttribute("name", navLocal.NamespaceURI);
navLocal.SetValue(cName);
navLocal.MoveToParent();
createComponent(VSGConfiguration, document, cType, cName, cDescription);
createLink(VSGConfiguration, document, cName, cName, kind, "SubplatformKind", String.Empty);
}
else
{
cName = navLocal.GetAttribute("name", navLocal.NamespaceURI);
// Create component
createComponent(VSGConfiguration, document, cType, cName, cDescription);
}
// Scenario Link
createLink(VSGConfiguration, document, navGlobal.SelectSingleNode("/Scenario").GetAttribute("name", navGlobal.NamespaceURI), eventName, cName, "Scenario", String.Empty);
#endregion
// Create parameters
#region parameters
if (navLocal.SelectSingleNode("Docked") != null)
createParameter(VSGConfiguration, document, cName, "Component", "Subplatform.DockedCount", (navLocal.SelectSingleNode("Docked/Count") == null) ? String.Empty : navLocal.SelectSingleNode("Docked/Count").Value, String.Empty);
#endregion
// Armaments
Int32 armamentNum = 0;
XPathNodeIterator itArmaments = navLocal.Select("Armament");
while (itArmaments.MoveNext())
{
itArmaments.Current.CreateAttribute(String.Empty, "name", String.Empty, cName + "Armament" + armamentNum++ + AME.Tools.ImportTool.Delimitter + "Armament");
createArmament(itArmaments.Current, document, navGlobal);
}
}
示例7: DeleteNil
public void DeleteNil(XPathNavigator node)
{
if (node.MoveToAttribute(
"nil", NamespaceManager.LookupNamespace("xsi")))
node.DeleteSelf();
}
示例8: GetAttributeValue
private string GetAttributeValue(XPathNavigator navigator, string name)
{
string val = "";
if (navigator.MoveToAttribute(name, ""))
{
val = navigator.Value;
navigator.MoveToParent();
}
return val;
}
示例9: AreEqual
/// <summary>
/// Checks if first navigator is equal to or subset of second.
/// </summary>
/// <param name="first">First navigator.</param>
/// <param name="second">Second navigator.</param>
/// <param name="checkSubset"><b>true</b> if we want to check that first
/// navigator and second has equal contents. <b>false</b> if contents of
/// first iterator should be subset of second iterator's contents.</param>
private static void AreEqual( XPathNavigator first, XPathNavigator second, bool checkSubset )
{
do
{
Assert.AreEqual( first.NodeType, second.NodeType, string.Format( "Types of nodes '{0}' and '{1}' must match.", MakePath( first ), MakePath( second ) ) );
if( first.NodeType != XPathNodeType.Root
&& first.NodeType != XPathNodeType.Whitespace
&& first.NodeType != XPathNodeType.Text
&& first.NodeType != XPathNodeType.Comment
)
{
Assert.AreEqual( first.LocalName, second.LocalName, string.Format( "Names of nodes '{0}' and '{1}' must match.", MakePath( first ), MakePath( second ) ) );
Assert.AreEqual( first.NamespaceURI, second.NamespaceURI, string.Format( "Namespaces of nodes '{0}' and '{1}' must match.", MakePath( first ), MakePath( second ) ) );
}
if( first.NodeType != XPathNodeType.Root &&
first.NodeType != XPathNodeType.Element &&
first.NodeType != XPathNodeType.Whitespace
)
Assert.AreEqual( first.Value, second.Value, string.Format( "Values of nodes '{0}' and '{1}' must match.", MakePath( first ), MakePath( second ) ) );
if( MoveToFirstAttribute( first ) )
{
if( ( !checkSubset && !MoveToFirstAttribute( second ) )
|| ( checkSubset && !second.MoveToAttribute( first.LocalName, first.NamespaceURI ) ) )
throw new AssertionException( string.Format( "Missing node '{0}' in second navigator.", MakePath( first ) ) );
do
{
Assert.AreEqual( first.NodeType, second.NodeType );
Assert.AreEqual( first.LocalName, second.LocalName );
Assert.AreEqual( first.NamespaceURI, second.NamespaceURI );
Assert.AreEqual( first.Value, second.Value, string.Format( "Values of attributes {0}:{1} must match.", first.Prefix, first.LocalName ) );
if( !MoveToNextAttribute( first ) )
{
if( !checkSubset && MoveToNextAttribute( second ) )
throw new AssertionException( string.Format( "Extra node '{0}' in second navigator.", MakePath( second ) ) );
break;
}
if( !checkSubset )
{
if( !MoveToNextAttribute( second ) )
throw new AssertionException( string.Format( "Missing node '{0}' in second navigator.", MakePath( first ) ) );
}
else
{
second.MoveToParent();
if( !second.MoveToAttribute( first.LocalName, first.NamespaceURI ) )
throw new AssertionException( string.Format( "Missing node '{0}' in second navigator.", MakePath( first ) ) );
}
}
while( true );
first.MoveToParent();
second.MoveToParent();
}
else if( !checkSubset && MoveToFirstAttribute( second ) )
{
throw new AssertionException( string.Format( "Nodes '{0}' and '{1}' must match.", MakePath( first ), MakePath( second ) ) );
}
/*
* We don't care how namespaces are defined.
*
if( first.MoveToFirstNamespace( XPathNamespaceScope.Local ) )
{
if( !second.MoveToFirstNamespace( XPathNamespaceScope.Local ) )
throw new AssertionException( string.Format( "Nodes '{0}' and '{1}' must match.", MakePath( first ), MakePath( second ) ) );
do
{
Assert.AreEqual( first.NodeType, second.NodeType );
Assert.AreEqual( first.LocalName, second.LocalName );
Assert.AreEqual( first.NamespaceURI, second.NamespaceURI );
Assert.AreEqual( first.Value, second.Value );
if( !first.MoveToNextNamespace( XPathNamespaceScope.Local ) )
{
if( second.MoveToNextNamespace( XPathNamespaceScope.Local ) )
throw new AssertionException( string.Format( "Nodes '{0}' and '{1}' must match.", MakePath( first ), MakePath( second ) ) );
break;
}
if( !second.MoveToNextNamespace( XPathNamespaceScope.Local ) )
throw new AssertionException( string.Format( "Nodes '{0}' and '{1}' must match.", MakePath( first ), MakePath( second ) ) );
}
while( true );
first.MoveToParent();
second.MoveToParent();
}
*/
if( first.MoveToFirstChild() )
//.........这里部分代码省略.........
示例10: CreateAttribute
public XPathNavigator CreateAttribute(string name, string namespaceUri, XPathNavigator source)
{
string prefix;
name = XmlConvert.EncodeLocalName(name);
if (IsRootNamespace(namespaceUri, out prefix))
prefix = CreateNamespace(prefix, namespaceUri, source);
source.CreateAttribute(prefix, name, namespaceUri, "");
source.MoveToAttribute(name, namespaceUri ?? "");
return source;
}
示例11: DeleteNil
public void DeleteNil(XPathNavigator node)
{
if (node.MoveToAttribute("nil", "http://www.w3.org/2001/XMLSchema-instance"))
node.DeleteSelf();
}