本文整理汇总了C#中System.Xml.Linq.XDocument.CreateReader方法的典型用法代码示例。如果您正苦于以下问题:C# XDocument.CreateReader方法的具体用法?C# XDocument.CreateReader怎么用?C# XDocument.CreateReader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Linq.XDocument
的用法示例。
在下文中一共展示了XDocument.CreateReader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public static async Task Run(CancellationToken cancellationToken)
{
Dme.Sbis.PackageBuilder pb = new Sbis.PackageBuilder
(
Dme.Svc.Out.Properties.Settings.Default.SbisOutputFolder,
Dme.Svc.Out.Properties.Settings.Default.RecipientID
);
while (!cancellationToken.IsCancellationRequested)
{
using (var context = new Dme.Core.DmeEntities())
{
XslCompiledTransform xsltMx1 = new XslCompiledTransform();
XslCompiledTransform xsltRep = new XslCompiledTransform();
xsltMx1.Load("mx1.xslt");
xsltRep.Load("rep.xslt");
var orders = await (from o in context.Order
where o.WfState == Dme.Core.Helper.WFSTATE.WMS_DONE && o.OrderType.ExportDocID == Dme.Core.Helper.EXPORTDOC.MX1
select o)
.ToListAsync(cancellationToken);
if (cancellationToken.IsCancellationRequested)
return;
foreach (var o in orders)
{
if (cancellationToken.IsCancellationRequested)
break;
try
{
// выгрузка реестра .sbis.xml
pb.Begin();
var xml = new XDocument(Dme.Core.Xml.OrderSerializer.ToXElement(o));
xsltMx1.Transform(xml.CreateReader(), pb.AddFile());
if(o.IsDocEqToFact == false)
xsltRep.Transform(xml.CreateReader(), pb.AddFile());
pb.Flush();
// помечаем файл как выгруженный
o.WfState = Dme.Core.Helper.WFSTATE.SBIS;
await context.SaveChangesAsync();
}
catch (Exception e)
{
log.Error(e);
}
}
}
if (cancellationToken.IsCancellationRequested)
return;
try
{
await Task.Delay(DELAY, cancellationToken);
}
catch (TaskCanceledException)
{
return;
}
}
}
示例2: ReadState1
//[Variation("XmlReader ReadState Initial", Priority = 0)]
public void ReadState1()
{
XDocument doc = new XDocument();
XmlReader r = doc.CreateReader();
if (r.ReadState != ReadState.Initial)
throw new TestFailedException("");
}
示例3: XmlNamespaceManagerEnhanced
public XmlNamespaceManagerEnhanced(XDocument doc)
: base(doc.CreateReader().NameTable)
{
var ns = doc.Root.GetDefaultNamespace();
if (ns != null && !string.IsNullOrWhiteSpace(ns.NamespaceName))
{
this.defaultNamespace = ns.NamespaceName;
AddNamespace(Common.DefaultNamespace, this.defaultNamespace);
}
var nslist = new Dictionary<string, string>();
var nav = doc.CreateNavigator();
while (nav.MoveToFollowing(XPathNodeType.Element))
{
var newFoundNapespaces = nav.GetNamespacesInScope(XmlNamespaceScope.All).Where(a => !nslist.ContainsKey(a.Key) && !this.HasNamespace(a.Key));
foreach (var item in newFoundNapespaces)
{
nslist.Add(item.Key, item.Value);
}
}
foreach (var item in nslist)
{
if (string.IsNullOrWhiteSpace(item.Key))
continue;
AddNamespace(item.Key, item.Value);
}
}
示例4: Deserialize
public object Deserialize(XDocument stateData, string keyType)
{
if (stateData == null)
{
return null;
}
using (var reader = stateData.CreateReader())
{
reader.ReadStartElement();
var typeValue = reader.ReadElementString();
// Ensure the Type was Specified
if (typeValue == null)
throw new ArgumentNullException("Unable to Read Xml Data for Abstract Type '" + keyType +
"' because no 'type' attribute was specified in the XML.");
var type = Type.GetType((new TypeNameWithoutVersion(typeValue)).Value);
// Check the Type is Found.
if (type == null)
throw new InvalidCastException("Unable to Read Xml Data for Abstract Type '" + keyType +
"' because the type specified in the XML was not found.");
return new XmlSerializer(type).Deserialize(reader.ReadSubtree());
}
}
示例5: TestRead
void TestRead(XDocument doc, int count)
{
string dsdPath = Utility.GetPath("lib\\StructureSample.xml");
var dsd = StructureMessage.Load(dsdPath);
var keyFamily = dsd.KeyFamilies[0];
int counter = 0;
using (var r = doc.CreateReader())
using (var reader = DataReader.Create(r, keyFamily))
{
var header = reader.ReadHeader();
Assert.IsNotNull(header);
while (reader.Read())
{
Assert.AreEqual(17, reader.Count());
//foreach (var item in reader)
// Console.Write("{0}={1},", item.Key, item.Value);
//Console.WriteLine();
counter++;
}
}
Assert.AreEqual(count, counter);
}
示例6: ExecScript
public static SqlXml ExecScript(SqlString Sql, SqlXml Options, SqlXml Input)
{
var XOutput = new XDocument(
new XElement("root",
new XElement("content")));
try
{
using (var q = new SqlCommand())
{
q.Connection = new SqlConnection("context connection=true");
q.CommandType = CommandType.Text;
q.CommandText = Sql.Value;
q.InitOptions(Options.Value);
q.Parameters.SetInput(Input.Value);
q.Connection.Open();
q.ExecuteNonQuery();
XOutput.Root.Add(q.Parameters.GetOutput());
q.Connection.Close();
}
}
catch (Exception ex)
{
XOutput.Root.Add(ex.ExceptionSerialize());
}
return new SqlXml(XOutput.CreateReader());
}
示例7: ExecQuery
public static SqlXml ExecQuery(SqlString Sql, SqlXml Options, SqlXml Input)
{
var XOutput = new XDocument(new XElement("root"));
try
{
using (var q = new SqlCommand())
{
q.Connection = new SqlConnection("context connection=true");
q.CommandType = CommandType.Text;
q.CommandText = Sql.Value;
q.InitOptions(Options.Value);
q.Parameters.SetInput(Input.Value);
q.Connection.Open();
var Result = q.ExecuteXmlReader();
if (Result.Read())
XOutput.Root.Element("content").Add(
XElement.Load(Result, LoadOptions.None));
q.Connection.Close();
}
}
catch (Exception ex)
{
XOutput.Root.Add(ex.ExceptionSerialize());
}
return new SqlXml(XOutput.CreateReader());
}
示例8: WriteProcessed
/// <summary>
/// Writes the results of XSLT transformation into the specified TextWriter.
/// </summary>
public static void WriteProcessed(string templateName, XsltArgumentList argumentList, XDocument data, TextWriter outStream)
{
using (XmlReader reader = data.CreateReader())
{
GetCompiledTransform(templateName).Transform(reader, argumentList, outStream);
}
}
示例9: Convert
public byte[] Convert(XDocument document)
{
XmlReader reader = document.CreateReader();
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
StartElement(reader.LocalName);
if (reader.IsEmptyElement)
{
EndElement(reader.LocalName);
}
break;
case XmlNodeType.EndElement:
EndElement(reader.LocalName);
break;
case XmlNodeType.Text:
Characters(reader.Value);
break;
default:
break;
}
}
return Encoding.UTF8.GetBytes(_output.ToString());
}
示例10: TransformXML
public static XDocument TransformXML(XDocument doc, string xslPath)
{
XDocument newdoc = new XDocument();
using (XmlWriter writer = newdoc.CreateWriter())
{
// Load the style sheet.
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(XmlReader.Create(xslPath));
// Execute the transform and output the results to a writer.
xslt.Transform(doc.CreateReader(), writer);
}
return newdoc;
/*
XslCompiledTransform transform = new XslCompiledTransform();
using (XmlReader reader = XmlReader.Create(xslPath))
{
transform.Load(reader);
}
StringWriter results = new StringWriter();
transform.Transform(doc, null, results);
var newdoc = new XmlDocument();
newdoc.LoadXml(results.ToString());
return newdoc;
* */
}
示例11: AddParameter
/// <summary>
/// Add a parameter to the current transformation
/// </summary>
public void AddParameter(string name, XDocument value)
{
DocumentBuilder docbuilder = processor.NewDocumentBuilder();
docbuilder.WhitespacePolicy = WhitespacePolicy.StripIgnorable;
XdmNode input = docbuilder.Build(value.CreateReader());
transform.SetParameter(new QName(name), input);
}
示例12: IsValidMessage
internal static bool IsValidMessage(XDocument doc, XDocument schema)
{
var schemas = new XmlSchemaSet();
schemas.Add("http://www.SDMX.org/resources/SDMXML/schemas/v2_0/message",
GetPath("lib\\SDMXMessage.xsd"));
if (schema != null)
{
using (var reader = schema.CreateReader())
{
schemas.Add(null, reader);
}
}
bool isValid = true;
doc.Validate(schemas, (s, args) =>
{
isValid = false;
if (args.Severity == XmlSeverityType.Warning)
Console.WriteLine("\tWarning: " + args.Message);
else
Console.WriteLine("\tError: " + args.Message);
});
return isValid;
}
示例13: v1
//[Variation("Reader Property empty doc", Priority = 0)]
public void v1()
{
XDocument doc = new XDocument();
XmlReader r = doc.CreateReader();
TestLog.Compare(r.AttributeCount, 0, "Error");
TestLog.Compare(r.BaseURI, "", "Error");
TestLog.Compare(r.CanReadBinaryContent, false, "Error");
TestLog.Compare(r.CanReadValueChunk, false, "Error");
TestLog.Compare(r.CanResolveEntity, false, "Error");
TestLog.Compare(r.Depth, 0, "Error");
TestLog.Compare(r.EOF, false, "Error");
TestLog.Compare(r.HasAttributes, false, "Error");
TestLog.Compare(r.HasValue, false, "Error");
TestLog.Compare(r.IsDefault, false, "Error");
TestLog.Compare(r.IsEmptyElement, false, "Error");
TestLog.Compare(r.LocalName, "", "Error");
TestLog.Compare(r.Name, "", "Error");
TestLog.Compare(r.NamespaceURI, "", "Error");
TestLog.Compare(r.Prefix, "", "Error");
TestLog.Compare(r.ReadState, ReadState.Initial, "Error");
TestLog.Compare(r.Value, "", "Error");
TestLog.Compare(r.XmlLang, "", "Error");
TestLog.Compare(r.XmlSpace, XmlSpace.None, "Error");
}
示例14: RetargetWithMetadataConverter
/// <remarks>Internal for testing.</remarks>
internal static void RetargetWithMetadataConverter(XDocument xdoc, Version targetSchemaVersion, MetadataConverterDriver converter)
{
Debug.Assert(xdoc != null, "xdoc != null");
Debug.Assert(EntityFrameworkVersion.IsValidVersion(targetSchemaVersion), "invalid target schema version");
var inputXml = new XmlDocument { PreserveWhitespace = true };
using (var reader = xdoc.CreateReader())
{
inputXml.Load(reader);
}
var outputXml = converter.Convert(inputXml, targetSchemaVersion);
if (outputXml != null)
{
// Dev10 Bug 550594: There is a bug in XmlEditor that prevents from deleting the root node
// unless the root node has previous sibling (like a comment or Xml declaration).
if (xdoc.Root.PreviousNode == null)
{
xdoc.Root.AddBeforeSelf(new XComment(""));
}
// update xml document with new root element
xdoc.Root.Remove();
using (var reader = new XmlNodeReader(outputXml))
{
var newDoc = XDocument.Load(reader);
xdoc.Add(newDoc.Root);
}
// Do not reload artifact here
// Until the transaction is commited, the XLinq representation of the parsed xml tree hasn't been generated yet.
}
}
示例15: ReadWrite
public void ReadWrite()
{
var person = new Person() { Name = "duraid", Age = 35 };
person.Addresses.Add(new Address() { Street = "Decelles", City = "Montreal" });
person.Addresses.Add(new Address() { Street = "Lincoln", City = "Montreal" });
var map = new PersonMap();
var doc = new XDocument();
using (var writer = doc.CreateWriter())
{
map.WriteXml(writer, person);
}
Person person2;
using (var reader = doc.CreateReader())
{
person2 = map.ReadXml(reader);
}
Assert.AreEqual(person.Name, person2.Name);
Assert.AreEqual(person.Age, person2.Age);
Assert.AreEqual(2, person.Addresses.Count);
person.Addresses.Where(a => a.Street == "Decelles" && a.City == "Montreal").Single();
person.Addresses.Where(a => a.Street == "Lincoln" && a.City == "Montreal").Single();
}