本文整理汇总了C#中System.Xml.Linq.XProcessingInstruction类的典型用法代码示例。如果您正苦于以下问题:C# XProcessingInstruction类的具体用法?C# XProcessingInstruction怎么用?C# XProcessingInstruction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XProcessingInstruction类属于System.Xml.Linq命名空间,在下文中一共展示了XProcessingInstruction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateProcessingInstructionSimple
/// <summary>
/// Tests the ProcessingInstruction constructor that takes a value.
/// </summary>
/// <param name="contextValue"></param>
/// <returns></returns>
//[Variation(Desc = "CreateProcessingInstructionSimple")]
public void CreateProcessingInstructionSimple()
{
try
{
new XProcessingInstruction(null, "abcd");
Validate.ExpectedThrow(typeof(ArgumentNullException));
}
catch (Exception ex)
{
Validate.Catch(ex, typeof(ArgumentNullException));
}
try
{
new XProcessingInstruction("abcd", null);
Validate.ExpectedThrow(typeof(ArgumentNullException));
}
catch (Exception ex)
{
Validate.Catch(ex, typeof(ArgumentNullException));
}
XProcessingInstruction c = new XProcessingInstruction("foo", "bar");
Validate.IsEqual(c.Target, "foo");
Validate.IsEqual(c.Data, "bar");
Validate.IsNull(c.Parent);
}
示例2: ProcessingInstructionEquals
/// <summary>
/// Validates the behavior of the Equals overload on XProcessingInstruction.
/// </summary>
/// <returns>true if pass, false if fail</returns>
//[Variation(Desc = "ProcessingInstructionEquals")]
public void ProcessingInstructionEquals()
{
XProcessingInstruction c1 = new XProcessingInstruction("targetx", "datax");
XProcessingInstruction c2 = new XProcessingInstruction("targetx", "datay");
XProcessingInstruction c3 = new XProcessingInstruction("targety", "datax");
XProcessingInstruction c4 = new XProcessingInstruction("targety", "datay");
XProcessingInstruction c5 = new XProcessingInstruction("targetx", "datax");
bool b1 = XNode.DeepEquals(c1, (XProcessingInstruction)null);
bool b3 = XNode.DeepEquals(c1, c1);
bool b4 = XNode.DeepEquals(c1, c2);
bool b5 = XNode.DeepEquals(c1, c3);
bool b6 = XNode.DeepEquals(c1, c4);
bool b7 = XNode.DeepEquals(c1, c5);
Validate.IsEqual(b1, false);
Validate.IsEqual(b3, true);
Validate.IsEqual(b4, false);
Validate.IsEqual(b5, false);
Validate.IsEqual(b6, false);
Validate.IsEqual(b7, true);
b1 = XNode.EqualityComparer.GetHashCode(c1) == XNode.EqualityComparer.GetHashCode(c5);
Validate.IsEqual(b1, true);
}
示例3: XProcessingInstruction
public XProcessingInstruction(XProcessingInstruction other)
{
if (other == null)
throw new ArgumentNullException ("other");
this.name = other.name;
this.data = other.data;
}
示例4: XProcessingInstruction
public XProcessingInstruction(XProcessingInstruction other)
{
if (other == null)
{
throw new ArgumentNullException("other");
}
this.target = other.target;
this.data = other.data;
}
示例5: ValidPIVariation
//[Variation(Priority = 0, Desc = "XProcessingInstruction - Valid Name")]
public void ValidPIVariation()
{
_runWithEvents = (bool)Params[0];
XProcessingInstruction toChange = new XProcessingInstruction("target", "data");
if (_runWithEvents) _eHelper = new EventsHelper(toChange);
toChange.Target = "newTarget";
if (_runWithEvents) _eHelper.Verify(XObjectChange.Name);
TestLog.Compare(toChange.Target.Equals("newTarget"), "Name did not change");
}
示例6: CreateProcessingInstructionSimple
public void CreateProcessingInstructionSimple()
{
Assert.Throws<ArgumentNullException>(() => new XProcessingInstruction(null, "abcd"));
Assert.Throws<ArgumentNullException>(() => new XProcessingInstruction("abcd", null));
XProcessingInstruction c = new XProcessingInstruction("foo", "bar");
Assert.Equal("foo", c.Target);
Assert.Equal("bar", c.Data);
Assert.Null(c.Parent);
}
示例7: CreateDocumentVerbose
// <?xml version="1.0"?>
// <?order alpha ascending?>
// <art xmlns='urn:art-org:art'>
// <period name='Renaissance' xmlns:a='urn:art-org:artists'>
// <a:artist>Leonardo da Vinci</a:artist>
// <a:artist>Michelangelo</a:artist>
// <a:artist><![CDATA[Donatello]]></a:artist>
// </period>
// <!-- insert period here -->
// </art>
public static XDocument CreateDocumentVerbose()
{
XNamespace nsArt = "urn:art-org:art";
XNamespace nsArtists = "urn:art-org:artists";
// create the document
XDocument document = new XDocument();
// create the xml declaration and
// set on the document
document.Declaration = new XDeclaration("1.0", null, null);
// create the art element and
// add to the document
XElement art = new XElement(nsArt + "art");
document.Add(art);
// create the order processing instruction and
// add before the art element
XProcessingInstruction pi = new XProcessingInstruction("order", "alpha ascending");
art.AddBeforeSelf(pi);
// create the period element and
// add to the art element
XElement period = new XElement(nsArt + "period");
art.Add(period);
// add the name attribute to the period element
period.SetAttributeValue("name", "Renaissance");
// create the namespace declaration xmlns:a and
// add to the period element
XAttribute nsdecl = new XAttribute(XNamespace.Xmlns + "a", nsArtists);
period.Add(nsdecl);
// create the artists elements and
// the underlying text nodes
period.SetElementValue(nsArtists + "artist", "Michelangelo");
XElement artist = new XElement(nsArtists + "artist", "Leonardo ", "da ", "Vinci");
period.AddFirst(artist);
artist = new XElement(nsArtists + "artist");
period.Add(artist);
XText cdata = new XText("Donatello");
artist.Add(cdata);
// create the comment and
// add to the art element
XComment comment = new XComment("insert period here");
art.Add(comment);
return document;
}
示例8: Process
public override IEnumerable< XNode > Process(XNode node)
{
XElement element = _AssumeElement( node );
Validation.RequireAttributes( element, AttrName.Name );
// PI name and value can have symbolic expansions or expressions
string pi_name =
_ProcessText( ( string ) element.Attribute( AttrName.Name ) ).GetTextValue();
string pi_val = _ProcessText( element.Value ).GetTextValue();
var pi = new XProcessingInstruction( pi_name, pi_val );
return new[] {pi};
}
示例9: CreateDocumentWithContent
public void CreateDocumentWithContent()
{
XDeclaration declaration = new XDeclaration("1.0", "utf-8", "yes");
XComment comment = new XComment("This is a document");
XProcessingInstruction instruction = new XProcessingInstruction("doc-target", "doc-data");
XElement element = new XElement("RootElement");
XDocument doc = new XDocument(declaration, comment, instruction, element);
Assert.Equal(new XNode[] { comment, instruction, element }, doc.Nodes());
}
示例10: set_ProcessingInstruction
public static XDocument set_ProcessingInstruction(this XDocument xDocument, string target, string data)
{
var processingInstruntion = xDocument.processingInstruction(target);
if (processingInstruntion.notNull())
processingInstruntion.Data = data;
else
{
var newProcessingInstruction = new XProcessingInstruction(target, data);//"xsl-stylesheet", "type=\"text/xsl\" href=\"LogStyle.xsl\"");
xDocument.AddFirst(newProcessingInstruction);
}
return xDocument;
}
示例11: CreateDocumentCopy
/// <summary>
/// Validate behavior of the XDocument copy/clone constructor.
/// </summary>
/// <returns>true if pass, false if fail</returns>
//[Variation(Desc = "CreateDocumentCopy")]
public void CreateDocumentCopy()
{
try
{
new XDocument((XDocument)null);
Validate.ExpectedThrow(typeof(ArgumentNullException));
}
catch (Exception ex)
{
Validate.Catch(ex, typeof(ArgumentNullException));
}
XDeclaration declaration = new XDeclaration("1.0", "utf-8", "yes");
XComment comment = new XComment("This is a document");
XProcessingInstruction instruction = new XProcessingInstruction("doc-target", "doc-data");
XElement element = new XElement("RootElement");
XDocument doc = new XDocument(declaration, comment, instruction, element);
XDocument doc2 = new XDocument(doc);
IEnumerator e = doc2.Nodes().GetEnumerator();
// First node: declaration
Validate.IsEqual(doc.Declaration.ToString(), doc2.Declaration.ToString());
// Next node: comment
Validate.IsEqual(e.MoveNext(), true);
Validate.Type(e.Current, typeof(XComment));
Validate.IsNotReferenceEqual(e.Current, comment);
XComment comment2 = (XComment)e.Current;
Validate.IsEqual(comment2.Value, comment.Value);
// Next node: processing instruction
Validate.IsEqual(e.MoveNext(), true);
Validate.Type(e.Current, typeof(XProcessingInstruction));
Validate.IsNotReferenceEqual(e.Current, instruction);
XProcessingInstruction instruction2 = (XProcessingInstruction)e.Current;
Validate.String(instruction2.Target, instruction.Target);
Validate.String(instruction2.Data, instruction.Data);
// Next node: element.
Validate.IsEqual(e.MoveNext(), true);
Validate.Type(e.Current, typeof(XElement));
Validate.IsNotReferenceEqual(e.Current, element);
XElement element2 = (XElement)e.Current;
Validate.ElementName(element2, element.Name.ToString());
Validate.Count(element2.Nodes(), 0);
// Should be end.
Validate.IsEqual(e.MoveNext(), false);
}
示例12: PI
// equals => hashcode should be the same
// - all "simple" node types
// - text vs. CDATA
// XDocument:
// - Normal mode
// - Concatenated text (Whitespace) nodes
// - Diffs in XDecl
// XElement:
// - Normal mode
// - same nodes, different order
// - comments inside the texts
// - same nodes, same order (positive)
//
// - Concatenated text nodes
// - string content vs. text node/s
// - empty string vs. empty text node
// - Multiple text nodes but the same value
// - adjacent text & CData
//
// - IsEmpty
// - Attribute order
// - Namespace declarations
// - local vs. in-scope
// - default redef.
//[Variation(Priority = 0, Desc = "PI normal", Params = new object[] { "PI", "click", "PI", "click", true })]
//[Variation(Priority = 0, Desc = "PI target=data", Params = new object[] { "PI", "PI", "PI", "PI", true })]
//[Variation(Priority = 0, Desc = "PI data = ''", Params = new object[] { "PI", "", "PI", "", true })]
//[Variation(Priority = 1, Desc = "PI data1!=data2", Params = new object[] { "PI", "click", "PI", "", false })]
//[Variation(Priority = 2, Desc = "PI target1!=target2!", Params = new object[] { "AAAAP", "click", "AAAAQ", "click", false })]
//[Variation(Priority = 2, Desc = "PI hashconflict I.", Params = new object[] { "AAAAP", "AAAAQ", "AAAAP", "AAAAQ", true })]
//[Variation(Priority = 2, Desc = "PI data=target, not the same", Params = new object[] { "PA", "PA", "PI", "PI", false })]
//[Variation(Priority = 2, Desc = "PI hashconflict II.", Params = new object[] { "AAAAP", "AAAAQ", "AAAAQ", "AAAAP", false })]
public void PI()
{
bool expected = (bool)Variation.Params[4];
XProcessingInstruction p1 = new XProcessingInstruction(Variation.Params[0] as string, Variation.Params[1] as string);
XProcessingInstruction p2 = new XProcessingInstruction(Variation.Params[2] as string, Variation.Params[3] as string);
VerifyComparison(expected, p1, p2);
XDocument doc = new XDocument(p1);
XElement e2 = new XElement("p2p", p2);
VerifyComparison(expected, p1, p2);
}
示例13: XPIEmptyStringShouldNotBeAllowed
//[Variation(Desc = "pi.Target = '' should not be allowed")]
public void XPIEmptyStringShouldNotBeAllowed()
{
XProcessingInstruction pi = new XProcessingInstruction("PI", "data");
try
{
pi.Target = "";
}
catch (ArgumentException)
{
return;
}
throw new TestException(TestResult.Failed, "");
}
示例14: NodeTypes
//[Variation(Desc = "NodeTypes")]
public void NodeTypes()
{
XDocument document = new XDocument();
XElement element = new XElement("x");
XText text = new XText("text-value");
XComment comment = new XComment("comment");
XProcessingInstruction processingInstruction = new XProcessingInstruction("target", "data");
Validate.IsEqual(document.NodeType, XmlNodeType.Document);
Validate.IsEqual(element.NodeType, XmlNodeType.Element);
Validate.IsEqual(text.NodeType, XmlNodeType.Text);
Validate.IsEqual(comment.NodeType, XmlNodeType.Comment);
Validate.IsEqual(processingInstruction.NodeType, XmlNodeType.ProcessingInstruction);
}
示例15: NodeTypes
public void NodeTypes()
{
XDocument document = new XDocument();
XElement element = new XElement("x");
XText text = new XText("text-value");
XComment comment = new XComment("comment");
XProcessingInstruction processingInstruction = new XProcessingInstruction("target", "data");
Assert.Equal(XmlNodeType.Document, document.NodeType);
Assert.Equal(XmlNodeType.Element, element.NodeType);
Assert.Equal(XmlNodeType.Text, text.NodeType);
Assert.Equal(XmlNodeType.Comment, comment.NodeType);
Assert.Equal(XmlNodeType.ProcessingInstruction, processingInstruction.NodeType);
}