本文整理匯總了C#中System.Xml.Linq.XElement.CreateReader方法的典型用法代碼示例。如果您正苦於以下問題:C# XElement.CreateReader方法的具體用法?C# XElement.CreateReader怎麽用?C# XElement.CreateReader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.Linq.XElement
的用法示例。
在下文中一共展示了XElement.CreateReader方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: GetRedirectList
private static AssemblyBinding GetRedirectList(XElement element)
{
var serializer = new XmlSerializer(typeof(AssemblyBinding));
if (!serializer.CanDeserialize(element.CreateReader()))
{
Error("Unable to deserialize assembly bindings, please ensure xml is valid", true);
return null;
}
return serializer.Deserialize(element.CreateReader()) as AssemblyBinding;
}
示例2: Xml2Html
/// <summary>
///將xml轉化為html;
///應用命名空間:
/// using System.Xml;
/// using System.Xml.XPath;
/// using System.Xml.Xsl;
/// </summary>
/// <param name="xmlDocument">XDocument對象</param>
/// <param name="xslFileStream">xsl數據流</param>
/// <param name="htmlFilePath">輸出路徑</param>
/// <returns>Exception</returns>
public static Exception Xml2Html(XElement xmlDocument, TextReader xslFileStream, string htmlFilePath)
{
Exception SuFlag = new Exception("操作成功");
try
{
//生成Html文件路徑
string HtmlFilePath = htmlFilePath;
XmlReader xst = XmlReader.Create(xslFileStream, new XmlReaderSettings() { DtdProcessing = DtdProcessing.Ignore});
XmlReader xmlreader = xmlDocument.CreateReader(ReaderOptions.OmitDuplicateNamespaces);
XPathDocument myXPathDoc = new XPathDocument(xmlreader);
XslCompiledTransform myXslTrans = new XslCompiledTransform();
xmlreader.Close();
//加載XSL文件
XsltSettings xs = XsltSettings.TrustedXslt;
myXslTrans.Load(xst, xs, new XmlUrlResolver());
XmlWriter myWriter = XmlTextWriter.Create(HtmlFilePath, myXslTrans.OutputSettings);
myXslTrans.Transform(myXPathDoc, null, myWriter);
myWriter.Close();
xst.Close();
}
catch (Exception ex)
{
SuFlag = ex;
}
return SuFlag;
}
示例3: XElement
public void LineNumber_and_LinePosition_return_line_and_column_number_for_text_if_XNodeReader_positioned_on_text_node()
{
var inputXml = new XElement("dummy", "value");
var mockModelProvider = new Mock<XmlModelProvider>();
mockModelProvider
.Setup(m => m.GetTextSpanForXObject(It.Is<XObject>(x => x == inputXml.FirstNode), It.IsAny<Uri>()))
.Returns(new TextSpan { iStartLine = 21, iStartIndex = 42, });
using (var reader = inputXml.CreateReader())
{
reader.Read();
reader.Read();
Assert.Equal(XmlNodeType.Text, reader.NodeType);
Assert.Equal("value", reader.Value);
using (var modelProvider = mockModelProvider.Object)
{
Assert.Equal(
21,
new XNodeReaderLineNumberService(modelProvider, reader, new Uri("urn:abc")).LineNumber);
Assert.Equal(
42,
new XNodeReaderLineNumberService(modelProvider, reader, new Uri("urn:abc")).LinePosition);
}
}
}
示例4: CreateXmlReader
private static XmlReader CreateXmlReader(EFArtifact artifact, XElement xobject)
{
var baseReader = xobject.CreateReader();
var lineNumberService = new XNodeReaderLineNumberService(artifact.XmlModelProvider, baseReader, artifact.Uri);
var proxyReader = new XmlReaderProxy(baseReader, artifact.Uri, lineNumberService);
return proxyReader;
}
示例5: Load
/// <summary>
/// Converts source XML with given transform with applying DSL
/// </summary>
/// <param name="xml"> </param>
/// <returns>XElement with data, converted by transform</returns>
/// <exception cref="XmlDslLoaderException">
/// <list type="bullet">
/// <item><description>cannot find transform file</description></item>
/// <item><description>any problem with underlined XmlDslDefinition</description></item>
/// </list>
/// </exception>
public XElement Load(XElement xml) {
if (null == xml.Element("transform")) return xml; //no dsl needed
var trdef = new XmlDslDefinition().Extract(xml);
var langfile = Resolver.Resolve(Rootdir+"/" + trdef.LangName + ".xslt", false);
if (!File.Exists(langfile))
{
throw new XmlDslLoaderException("Не возможно найти файл XML языка" + langfile);
}
var xsl = new XslCompiledTransform();
if(trdef.NeedPrepareXslt) {
var xsltcontent = XElement.Load(langfile);
xsltcontent = trdef.PrepareXslt(xsltcontent);
var resolver = new XmlDslRootBasedXmlUrlResolver(langfile);
xsl.Load(xsltcontent.CreateReader(),XsltSettings.TrustedXslt,resolver);
}else {
xsl.Load(langfile, XsltSettings.TrustedXslt, new XmlUrlResolver());
}
var args = trdef.CreateArguments();
var sw = new StringWriter();
using (var xw = XmlWriter.Create(sw)) {
xsl.Transform(xml.CreateReader(),args,xw);
xw.Flush();
}
return XElement.Parse(sw.ToString());
}
示例6: Create
private static StorageException Create(int httpStatusCode, XElement extendedErrorElement)
{
// Unfortunately, the RequestResult properties are all internal-only settable. ReadXml is the only way to
// create a populated RequestResult instance.
XElement requestResultElement = new XElement("RequestResult",
new XElement("HTTPStatusCode", httpStatusCode),
new XElement("HttpStatusMessage"),
new XElement("TargetLocation"),
new XElement("ServiceRequestID"),
new XElement("ContentMd5"),
new XElement("Etag"),
new XElement("RequestDate"),
new XElement("StartTime", DateTime.Now),
new XElement("EndTime", DateTime.Now),
extendedErrorElement);
RequestResult result = new RequestResult();
using (XmlReader reader = requestResultElement.CreateReader())
{
result.ReadXml(reader);
}
return new StorageException(result, null, null);
}
示例7: GetType
/// <summary>
/// Converts an object into its XML representation.
/// </summary>
/// <param name="writer">The <see cref="T:System.Xml.XmlWriter"/> stream to which the object is serialized.</param>
void IXmlSerializable.WriteXml(XmlWriter writer)
{
var type = GetType();
var element = new XElement(type.Name);
var serializer = SerializationFactory.GetXmlSerializer();
serializer.Serialize(this, new XmlSerializationContextInfo(element, this));
// The serializer gives us the full element, but we only need the actual content. According to
// http://stackoverflow.com/questions/3793/best-way-to-get-innerxml-of-an-xelement, this method is the fastest:
var reader = element.CreateReader();
reader.MoveToContent();
// CTL-710: fix attributes on top level elements
if (reader.HasAttributes)
{
for (int i = 0; i < reader.AttributeCount; i++)
{
reader.MoveToAttribute(i);
var attributePrefix = reader.Prefix;
var attributeLocalName = reader.LocalName;
var attributeNs = reader.NamespaceURI;
var attributeValue = reader.Value;
writer.WriteAttributeString(attributePrefix, attributeLocalName, attributeNs, attributeValue);
}
reader.MoveToElement();
}
var elementContent = reader.ReadInnerXml();
writer.WriteRaw(elementContent);
}
示例8: When_transforming_xml_to_html_output_is_generated
public void When_transforming_xml_to_html_output_is_generated()
{
XElement element = new XElement("ApiCheckResult");
MemoryStream sut = new MemoryStream();
Assert.DoesNotThrow(() => XmlTransformer.TransformToHtml(element.CreateReader(), sut));
Assert.Greater(sut.Length, 0);
}
示例9: Create
/// <summary>
/// Creates the specified path to config file.
/// </summary>
/// <param name="sectionElement">The section element.</param>
/// <returns>The strongly typed consfig section</returns>
private object Create(XElement sectionElement)
{
var typeName = sectionElement.HasAttributes ? sectionElement.Attributes()
.SingleOrDefault(x => x.Name.LocalName.Equals("Type", StringComparison.InvariantCultureIgnoreCase)).Value
: string.Empty;
var ser = new XmlSerializer(Type.GetType(typeName));
return ser.Deserialize(sectionElement.CreateReader());
}
示例10: ConvertToErrorHtml
private string ConvertToErrorHtml(XElement xml) {
var xslt = GetType().Assembly.ReadManifestResource("errors.xslt");
var cxslt = new XslCompiledTransform();
cxslt.Load(XmlReader.Create(new StringReader(xslt)),XsltSettings.TrustedXslt, new XmlUrlResolver());
var sw = new StringWriter();
cxslt.Transform(xml.CreateReader(),new XsltArgumentList(),sw);
return sw.ToString();
}
示例11: GetXmlNode
static XmlNode GetXmlNode(XElement element)
{
using (XmlReader xmlReader = element.CreateReader())
{
var xmlDoc = new XmlDocument();
xmlDoc.Load(xmlReader);
return xmlDoc;
}
}
示例12: GetXmlNamespaceManager
public static XmlNamespaceManager GetXmlNamespaceManager(XElement elem)
{
XmlNamespaceManager xnsm = new XmlNamespaceManager(elem.CreateReader().NameTable);
foreach (var key in TypeNamespaces.AllKeys) {
xnsm.AddNamespace(TypeNamespaces[key], key);
}
return xnsm;
}
示例13: Expression
public static IExpression Expression(this IExpressionsManager manager, XElement element)
{
Configuration config = new Configuration();
IConfigurationElement configElement = config.AddSection("expression extensions").AddElement("expression");
configElement.ReadXml(element.CreateReader());
IExpression expression = manager.Token(configElement.GetAttributeReference("type").Value.ToString()) as IExpression;
if (null != expression)
expression.Make(configElement, manager);
return expression;
}
示例14: Execute
private void Execute(XslCompiledTransform xslt, XElement xml, XsltArgumentList args, string path) {
Directory.CreateDirectory(Path.GetDirectoryName(path));
if (NoXml)
{
using (var tw = new StreamWriter(path))
{
xslt.Transform(xml.CreateReader(),args,tw);
tw.Flush();
}
}
else
{
using (var xw = XmlWriter.Create(path))
{
xslt.Transform(xml.CreateReader(), args, xw, new BSharpXmlResolver(Project));
xw.Flush();
}
}
}
示例15: DownCastToSurfaceElement
private static XmlElement DownCastToSurfaceElement(XElement element)
{
XNamespace ns = "http://www.opengis.net/gml/3.2";
XmlDocument doc = new XmlDocument();
element.Name = ns+ "Surface";
return doc.ReadNode(element.CreateReader()) as XmlElement;
}