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
<?xml version="1.0" encoding="UTF-8"?> | |
<?xml-stylesheet type="text/xsl" href="xxxxx.xslt"?> | |
<xxx:xxxx>data</xxx:xxx> |
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
using System; | |
using System.Text; | |
using System.Xml; | |
using System.Xml.Xsl; | |
public static class XmlExtension | |
{ | |
const int HREF_LENGTH = 6; | |
public static String FindXsltFilePath(this XmlDocument doc) | |
{ | |
String result = String.Empty; | |
XmlProcessingInstruction xmlStylesheet = null; | |
foreach (XmlNode xmlNode in doc.ChildNodes) | |
{ | |
if (xmlNode is XmlProcessingInstruction) | |
{ | |
xmlStylesheet = (XmlProcessingInstruction)xmlNode; | |
if (xmlStylesheet.Value.Length > 0) | |
{ | |
string[] valueHref = xmlStylesheet.Value.Split(' '); | |
if (valueHref.Length > 1) result = FindLinkValue(valueHref[1]); | |
} | |
break; | |
} | |
} | |
return result; | |
} | |
private static String FindLinkValue(String href) | |
{ | |
return href.Substring(HREF_LENGTH, href.Length - HREF_LENGTH).Replace("\"", ""); | |
} | |
} |
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
using System; | |
using System.Xml; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
XmlDocument doc = new XmlDocument(); | |
doc.PreserveWhitespace = true; | |
doc.Load("yourfile.xml"); | |
String xsltFilePath = doc.FindXsltFilePath(); | |
} | |
} |