-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
57 additions
and
122 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
snippets/csharp/System.Xml.XPath/Extensions/CreateNavigator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System.Xml; | ||
using System.Xml.Linq; | ||
using System.Xml.XPath; | ||
using System.Xml.Xsl; | ||
|
||
string xslMarkup = @"<?xml version='1.0'?> | ||
<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'> | ||
<xsl:template match='/Parent'> | ||
<Root> | ||
<C1><xsl:value-of select='Child1'/></C1> | ||
<C2><xsl:value-of select='Child2'/></C2> | ||
</Root> | ||
</xsl:template> | ||
</xsl:stylesheet>"; | ||
|
||
XDocument xmlTree = new( | ||
new XElement("Parent", | ||
new XElement("Child1", "Child1 data"), | ||
new XElement("Child2", "Child2 data") | ||
) | ||
); | ||
|
||
XDocument newTree = new(); | ||
using (XmlWriter writer = newTree.CreateWriter()) | ||
{ | ||
// Load the style sheet. | ||
XslCompiledTransform xslt = new(); | ||
xslt.Load(XmlReader.Create(new StringReader(xslMarkup))); | ||
|
||
// Execute the transform and output the results to a writer. | ||
xslt.Transform(xmlTree.CreateNavigator(), writer); | ||
} | ||
|
||
Console.WriteLine(newTree); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFrameworks>net6.0</TargetFrameworks> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters