本文整理匯總了C#中System.Xml.XmlElement.InsertBefore方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlElement.InsertBefore方法的具體用法?C# XmlElement.InsertBefore怎麽用?C# XmlElement.InsertBefore使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.XmlElement
的用法示例。
在下文中一共展示了XmlElement.InsertBefore方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: AddConformanceClaims
internal static void AddConformanceClaims(XmlElement documentation, WsiProfiles claims)
{
claims &= WsiProfiles.BasicProfile1_1;
if (claims != WsiProfiles.None)
{
WsiProfiles conformanceClaims = GetConformanceClaims(documentation);
claims &= ~conformanceClaims;
if (claims != WsiProfiles.None)
{
XmlDocument ownerDocument = documentation.OwnerDocument;
if ((claims & WsiProfiles.BasicProfile1_1) != WsiProfiles.None)
{
XmlElement newChild = ownerDocument.CreateElement("wsi", "Claim", "http://ws-i.org/schemas/conformanceClaim/");
newChild.SetAttribute("conformsTo", "http://ws-i.org/profiles/basic/1.1");
documentation.InsertBefore(newChild, null);
}
}
}
}
示例2: AddConformanceClaims
internal static void AddConformanceClaims(XmlElement documentation, WsiProfiles claims) {
//
claims &= SupportedClaims;
if (claims == WsiProfiles.None)
return;
// check already presend claims
WsiProfiles existingClaims = GetConformanceClaims(documentation);
claims &= ~existingClaims;
if (claims == WsiProfiles.None)
return;
XmlDocument d = documentation.OwnerDocument;
if ((claims & WsiProfiles.BasicProfile1_1) != 0) {
XmlElement claim = d.CreateElement(Soap.ClaimPrefix, Soap.Element.Claim, Soap.ConformanceClaim);
claim.SetAttribute(Soap.Attribute.ConformsTo, Soap.BasicProfile1_1);
documentation.InsertBefore(claim, null);
}
}
示例3: AddSignature
private void AddSignature(XmlElement parent)
{
body.Normalize();
SignedXml signed = new SamlSignedXml(body);
signed.SigningKey = sessionCert.PrivateKey;
signed.SignedInfo.CanonicalizationMethod = SignedXml.XmlDsigExcC14NTransformUrl;
signed.KeyInfo = new KeyInfo();
signed.KeyInfo.AddClause(new KeyInfoX509Data(sessionCert, X509IncludeOption.EndCertOnly));
Reference requestRef = new Reference("#" + requestId);
requestRef.AddTransform(new XmlDsigEnvelopedSignatureTransform());
requestRef.AddTransform(new XmlDsigExcC14NTransform());
signed.AddReference(requestRef);
signed.ComputeSignature();
parent.InsertBefore(signed.GetXml(), parent.FirstChild);
}
示例4: WriteActionGroups
protected void WriteActionGroups (ObjectWriter writer, XmlElement elem)
{
if (writer.Format == FileFormat.Native) {
if (actionGroups != null) {
foreach (ActionGroup actionGroup in actionGroups)
elem.InsertBefore (actionGroup.Write (writer), elem.FirstChild);
}
}
}
示例5: BeautifyElement
private void BeautifyElement(XmlElement e, int indent)
{
StringBuilder s = new StringBuilder();
s.Append('\n');
for (int i = 0; i < indent; i++)
{
s.Append(' ');
}
string afterContent = s.ToString();
for (int i_1 = 0; i_1 < prettyIndent; i_1++)
{
s.Append(' ');
}
string beforeContent = s.ToString();
// We "mark" all the nodes first; if we tried to do this loop otherwise, it would behave unexpectedly (the inserted nodes
// would contribute to the length and it might never terminate).
List<System.Xml.XmlNode> toIndent = new List<System.Xml.XmlNode>();
bool indentChildren = false;
for (int i_2 = 0; i_2 < e.ChildNodes.Count; i_2++)
{
if (i_2 == 1)
{
indentChildren = true;
}
if (e.ChildNodes.Item(i_2) is XmlText)
{
toIndent.Add(e.ChildNodes.Item(i_2));
}
else
{
indentChildren = true;
toIndent.Add(e.ChildNodes.Item(i_2));
}
}
if (indentChildren)
{
for (int i_3 = 0; i_3 < toIndent.Count; i_3++)
{
e.InsertBefore(e.OwnerDocument.CreateTextNode(beforeContent), toIndent[i_3]);
}
}
XmlNodeList nodes = e.ChildNodes;
List<XmlElement> list = new List<XmlElement>();
for (int i_4 = 0; i_4 < nodes.Count; i_4++)
{
if (nodes.Item(i_4) is XmlElement)
{
list.Add((XmlElement)nodes.Item(i_4));
}
}
foreach (XmlElement elem in list)
{
BeautifyElement(elem, indent + prettyIndent);
}
if (indentChildren)
{
e.AppendChild(e.OwnerDocument.CreateTextNode(afterContent));
}
}
示例6: AppendActionToXmlModel
/// <summary>
/// Appends the specified action to the specified XML action model. The "group-hint"
/// attribute of the action to be inserted is compared with the "group-hint" of the
/// actions in the xml model and an appropriate place to insert the action is determined
/// based on the MatchScore method of the <see cref="GroupHint"/>.
/// </summary>
/// <param name="xmlActionModel">the "action-model" node to insert an action into</param>
/// <param name="action">the action to be inserted</param>
/// <returns>a boolean indicating whether anything was added/removed/modified</returns>
private static bool AppendActionToXmlModel(XmlDocument document, XmlElement xmlActionModel, IAction action)
{
if (null != FindXmlAction(xmlActionModel, action))
return false;
XmlNode insertionPoint = null;
bool insertBefore = false;
int currentGroupScore = 0;
foreach (XmlElement xmlAction in xmlActionModel.GetElementsByTagName("action"))
{
string hint = xmlAction.GetAttribute("group-hint");
var groupHint = new GroupHint(hint);
int groupScore = action.GroupHint.MatchScore(groupHint);
if (groupScore > 0 && groupScore >= Math.Abs(currentGroupScore))
{
//"greater than" current score
insertionPoint = xmlAction;
currentGroupScore = groupScore;
insertBefore = false;
}
else if (groupScore < 0 && Math.Abs(groupScore) > Math.Abs(currentGroupScore))
{
//"less than"
insertionPoint = xmlAction;
currentGroupScore = groupScore;
insertBefore = true;
}
}
XmlElement newXmlAction = CreateXmlAction(document, action);
if (insertionPoint != null)
{
if (insertBefore)
xmlActionModel.InsertBefore(newXmlAction, insertionPoint);
else
xmlActionModel.InsertAfter(newXmlAction, insertionPoint);
}
else
xmlActionModel.AppendChild(newXmlAction);
return true;
}
示例7: InsertBefore
internal void InsertBefore(XmlElement parent, XmlElement child, XmlElement reference)
{
parent.InsertBefore(child, reference);
}
示例8: InsertTransformElement
protected override void InsertTransformElement(XmlElement targetElement, XmlElement transformElement)
{
targetElement.InsertBefore(transformElement, targetElement.ChildNodes.OfType<XmlNode>().FirstOrDefault());
}
示例9: ExtractSharedValues
private void ExtractSharedValues(XmlElement arrayNode)
{
var childs = GetChild(arrayNode);
if (childs.Count < 2) return;//No defaults for less than two item in the array
if (arrayNode.SelectNodes("Item[@ElementDataType]").Count > 0)//Dont make default for different Data types
return;
Dictionary<string, int> dic = new Dictionary<string, int>();
Dictionary<string, string> propertyValue = new Dictionary<string, string>();
foreach (XmlNode property in arrayNode.SelectNodes("Item/Property"))
{
string key = property.Attributes["PropertyName"].Value;
if (propertyValue.ContainsKey(key) && propertyValue[key] != property.InnerXml)
dic.Remove(key);
else
{
propertyValue[key] = property.InnerXml;
if (dic.ContainsKey(key)) dic[key]++;
else dic[key] = 1;
}
}
var defaultItem = xmlDoc.CreateElement("ItemDefaults");
foreach (var item in dic)
{
if (item.Value < childs.Count) continue;
var nodes = arrayNode.SelectNodes(string.Format("Item/Property[@PropertyName=\"{0}\"]", item.Key));
foreach (XmlNode node in nodes)
node.ParentNode.RemoveChild(node);
defaultItem.AppendChild(nodes[0]);
}
if (GetChild(defaultItem).Count > 0)
arrayNode.InsertBefore(defaultItem, childs[0]);
}
示例10: ExecuteCore
protected override void ExecuteCore(XmlElement element)
{
var child = CreateNode(element);
if (!string.IsNullOrEmpty(After))
{
try
{
if (After == "self")
{
element.ParentNode.InsertAfter(child, element);
return;
}
var node = element.SelectSingleNode(After);
if (node != null)
{
element.InsertAfter(child, node);
return;
}
}
catch (XPathException e)
{
var message = string.Format("'{0}' is not a valid XPath expression.", After);
throw new TaskExecutionException(message, e);
}
catch (ArgumentException)
{
// The XPath expression is not valid IN THIS CONTEXT, e.g. an attribute was selected
}
}
if (!string.IsNullOrEmpty(Before))
{
try
{
if (Before == "self")
{
element.ParentNode.InsertBefore(child, element);
return;
}
var node = element.SelectSingleNode(Before);
if (node != null)
{
element.InsertBefore(child, node);
return;
}
}
catch (XPathException e)
{
var message = string.Format("'{0}' is not a valid XPath expression.", Before);
throw new TaskExecutionException(message, e);
}
catch (ArgumentException)
{
// The XPath expression is not valid IN THIS CONTEXT, e.g. an attribute was selected
}
}
element.AppendChild(child);
}
示例11: CollectAntCodeCoverageForNode
private void CollectAntCodeCoverageForNode(string reportDirectory, string include, string exclude, XmlElement node, XmlDocument buildXml, XmlNode instrumentNode, string instrumentedClassesDirectory, string dataFile)
{
// add instrument node befor the test node.
var parentNode = node.ParentNode;
parentNode.InsertBefore(instrumentNode, node);
node.SetAttribute("fork", "true");
_executionContext.Debug(StringUtil.Format(CodeCoverageConstants.SettingAttributeTemplate, "fork", "true", "test"));
RemoveSysNodes(node);
var coberturaCoverageElement = buildXml.CreateElement("sysproperty");
coberturaCoverageElement.SetAttribute("key", "net.sourceforge.cobertura.datafile");
coberturaCoverageElement.SetAttribute("file", dataFile);
node.InsertBefore(coberturaCoverageElement, node.FirstChild);
var instrumentElement = buildXml.CreateElement("classpath");
instrumentElement.SetAttribute("location", instrumentedClassesDirectory);
node.InsertAfter(instrumentElement, node.FirstChild);
var classPathElement = buildXml.CreateElement("classpath");
classPathElement.SetAttribute("refid", CodeCoverageConstants.CoberturaClassPathString);
node.InsertAfter(classPathElement, node.LastChild);
}
示例12: AddFootnoteResource
/// <summary>
///
/// </summary>
/// <param name="fp"></param>
/// <param name="parentEle"></param>
protected void AddFootnoteResource( FootnoteProperty fp, XmlElement parentEle )
{
XmlElement resource = null;
resource = this.xDoc.CreateElement(DocumentBase.XBRL_LINKBASE_PREFIX, FOOTNOTE_RESOURCE, DocumentBase.XBRL_LINKBASE_URL);
XmlAttribute resAttr = xDoc.CreateAttribute( DocumentBase.XLINK_PREFIX, TYPE, DocumentBase.XLINK_URI );
resAttr.Value = RESOURCE;
resource.SetAttributeNode( resAttr );
XmlAttribute resRoleAttr = xDoc.CreateAttribute( DocumentBase.XLINK_PREFIX, ROLE, DocumentBase.XLINK_URI );
resRoleAttr.Value = FOOTNOTE_RESOURCE_ARCROLE;
resource.SetAttributeNode( resRoleAttr );
XmlAttribute labelAttr = xDoc.CreateAttribute( DocumentBase.XLINK_PREFIX, LABEL, DocumentBase.XLINK_URI );
labelAttr.Value = fp.Id;
resource.SetAttributeNode( labelAttr );
XmlAttribute langAttr = xDoc.CreateAttribute(XML, LANG, DocumentBase.XBRL_INSTANCE_URL);
langAttr.Value = fp.language;
resource.SetAttributeNode( langAttr );
try
{
resource.InnerXml = fp.markupData;
}
catch (Exception)
{
resource.InnerText = fp.markupData;
}
parentEle.AppendChild(resource);
if ( writeComments )
{
XmlComment locComment = xDoc.CreateComment( TraceUtility.FormatStringResource( "XBRLParser.Info.InstanceDocMarkupAddress", fp.address ) );
parentEle.InsertBefore(locComment, resource);
}
fp.HasBeenWritten = true;
}
示例13: AddFootnoteLocator
private void AddFootnoteLocator(MarkupProperty mp, XmlElement parentElement)
{
XmlElement locator = null;
locator = xDoc.CreateElement(DocumentBase.XBRL_LINKBASE_PREFIX, LOC, DocumentBase.XBRL_LINKBASE_URL);
XmlAttribute typeAttr = xDoc.CreateAttribute( DocumentBase.XLINK_PREFIX, TYPE, DocumentBase.XLINK_URI );
typeAttr.Value = LOCATOR;
locator.SetAttributeNode( typeAttr );
XmlAttribute hrefAttr = xDoc.CreateAttribute( DocumentBase.XLINK_PREFIX, HREF, DocumentBase.XLINK_URI );
hrefAttr.Value = string.Format( HREF_FORMAT, string.Empty, mp.Id );
locator.SetAttributeNode( hrefAttr );
XmlAttribute labelAttr = xDoc.CreateAttribute( DocumentBase.XLINK_PREFIX, LABEL, DocumentBase.XLINK_URI );
labelAttr.Value = string.Format( LABEL_FORMAT, mp.Id );
locator.SetAttributeNode( labelAttr );
parentElement.AppendChild(locator);
if (writeComments && mp.xmlElement != null)
{
XmlComment locComment = xDoc.CreateComment( TraceUtility.FormatStringResource( "XBRLParser.Info.InstanceDocFootnoteMarkupAddress", mp.address, mp.xmlElement.Name ) );
parentElement.InsertBefore(locComment, locator);
}
}