本文整理汇总了C#中System.IO.XmlReader类的典型用法代码示例。如果您正苦于以下问题:C# XmlReader类的具体用法?C# XmlReader怎么用?C# XmlReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XmlReader类属于System.IO命名空间,在下文中一共展示了XmlReader类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: XDeclaration
internal XDeclaration(XmlReader r)
{
_version = r.GetAttribute("version");
_encoding = r.GetAttribute("encoding");
_standalone = r.GetAttribute("standalone");
r.Read();
}
开发者ID:er0dr1guez,项目名称:corefx,代码行数:7,代码来源:XDeclaration.cs
示例2: StartParsing
public void StartParsing(XmlReader reader, string targetNamespace) {
this.reader = reader;
positionInfo = PositionInfo.GetPositionInfo(reader);
namespaceManager = reader.NamespaceManager;
if (namespaceManager == null) {
namespaceManager = new XmlNamespaceManager(nameTable);
isProcessNamespaces = true;
}
else {
isProcessNamespaces = false;
}
while (reader.NodeType != XmlNodeType.Element && reader.Read()) {}
markupDepth = int.MaxValue;
schemaXmlDepth = reader.Depth;
SchemaType rootType = schemaNames.SchemaTypeFromRoot(reader.LocalName, reader.NamespaceURI);
string code;
if (!CheckSchemaRoot(rootType, out code)) {
throw new XmlSchemaException(code, reader.BaseURI, positionInfo.LineNumber, positionInfo.LinePosition);
}
if (schemaType == SchemaType.XSD) {
schema = new XmlSchema();
schema.BaseUri = new Uri(reader.BaseURI, UriKind.RelativeOrAbsolute);
builder = new XsdBuilder(reader, namespaceManager, schema, nameTable, schemaNames, eventHandler);
}
else {
Debug.Assert(schemaType == SchemaType.XDR);
xdrSchema = new SchemaInfo();
xdrSchema.SchemaType = SchemaType.XDR;
builder = new XdrBuilder(reader, namespaceManager, xdrSchema, targetNamespace, nameTable, schemaNames, eventHandler);
((XdrBuilder)builder).XmlResolver = xmlResolver;
}
}
开发者ID:uQr,项目名称:referencesource,代码行数:35,代码来源:Parser.cs
示例3: XmlCountingReader
internal XmlCountingReader(XmlReader xmlReader)
{
if (xmlReader == null)
throw new ArgumentNullException("xmlReader");
this.innerReader = xmlReader;
this.advanceCount = 0;
}
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:7,代码来源:XmlCountingReader.cs
示例4: XmlCountingReader
internal XmlCountingReader(XmlReader xmlReader)
{
if (xmlReader == null)
throw new ArgumentNullException(nameof(xmlReader));
_innerReader = xmlReader;
_advanceCount = 0;
}
开发者ID:geoffkizer,项目名称:corefx,代码行数:7,代码来源:XmlCountingReader.cs
示例5: StartParsing
internal void StartParsing(XmlReader reader, string targetNamespace, SchemaInfo schemaInfo) {
this.reader = reader;
positionInfo = PositionInfo.GetPositionInfo(reader);
this.namespaceManager = reader.NamespaceManager;
if (this.namespaceManager == null) {
this.namespaceManager = new XmlNamespaceManager(this.nameTable);
this.isProcessNamespaces = true;
}
else {
this.isProcessNamespaces = false;
}
while (this.reader.NodeType != XmlNodeType.Element && this.reader.Read()) {}
this.markupDepth = int.MaxValue;
this.schemaXmlDepth = reader.Depth;
XmlQualifiedName qname = new XmlQualifiedName(this.reader.LocalName, XmlSchemaDatatype.XdrCanonizeUri(this.reader.NamespaceURI, this.nameTable, this.schemaNames));
if (this.schemaNames.IsXDRRoot(qname)) {
Debug.Assert(schemaInfo != null);
schemaInfo.SchemaType = SchemaType.XDR;
this.schema = null;
this.builder = new XdrBuilder(reader, this.namespaceManager, schemaInfo, targetNamespace, this.nameTable, this.schemaNames, this.validationEventHandler);
}
else if (this.schemaNames.IsXSDRoot(qname)) {
if (schemaInfo != null) {
schemaInfo.SchemaType = SchemaType.XSD;
}
this.schema = new XmlSchema();
this.schema.BaseUri = reader.BaseURI;
this.builder = new XsdBuilder(reader, this.namespaceManager, this.schema, this.nameTable, this.schemaNames, this.validationEventHandler);
}
else {
throw new XmlSchemaException(Res.Sch_SchemaRootExpected, reader.BaseURI, positionInfo.LineNumber, positionInfo.LinePosition);
}
}
开发者ID:ArildF,项目名称:masters,代码行数:35,代码来源:parser.cs
示例6: XPathDocument
/// <summary>
/// Create a new document from "reader", with whitespace handling controlled according to "space".
/// </summary>
public XPathDocument(XmlReader reader, XmlSpace space)
{
if (reader == null)
throw new ArgumentNullException(nameof(reader));
LoadFromReader(reader, space);
}
开发者ID:Corillian,项目名称:corefx,代码行数:10,代码来源:XPathDocument.cs
示例7: Load
public void Load(XmlReader stylesheet, XmlResolver resolver)
{
if (stylesheet == null)
{
throw new ArgumentNullException(nameof(stylesheet));
}
Load(new XPathDocument(stylesheet, XmlSpace.Preserve), resolver);
}
开发者ID:alessandromontividiu03,项目名称:corefx,代码行数:8,代码来源:XslTransform.cs
示例8: XmlCustomReader
public XmlCustomReader(TextReader textReader, XmlReaderSettings settings, string baseUri)
{
XmlReader w = ReaderHelper.Create(textReader, settings, baseUri);
XmlReaderSettings wsettings = new XmlReaderSettings();
wsettings.CheckCharacters = true;
wsettings.DtdProcessing = DtdProcessing.Ignore;
wsettings.ConformanceLevel = ConformanceLevel.Auto;
_wrappedreader = ReaderHelper.Create(w, wsettings);
}
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:9,代码来源:CReader.cs
示例9: Init
private void Init( XmlReader reader ) {
XmlValidatingReader vr = null;
try {
vr = new XmlValidatingReader( reader );
vr.EntityHandling = EntityHandling.ExpandEntities;
vr.ValidationType = ValidationType.None;
vr.ValidationEventHandler += new ValidationEventHandler(ValidationCallback);
Load( vr );
}
finally {
vr.Close();
reader.Close();
}
}
开发者ID:ArildF,项目名称:masters,代码行数:14,代码来源:xpathdocument.cs
示例10: CheckIgnores
public bool CheckIgnores(XmlReader reader, bool pi, bool comm, bool ws)
{
if (reader == null)
return false;
_commentCount = 0;
_piCount = 0;
_wsCount = 0;
while (reader.Read())
{
if (XmlNodeType.ProcessingInstruction == reader.NodeType)
{
++_piCount;
}
if (XmlNodeType.SignificantWhitespace == reader.NodeType)
{
++_wsCount;
}
if (XmlNodeType.Comment == reader.NodeType)
{
++_commentCount;
}
}
if (pi && _piCount > 0)
{
CError.WriteLineIgnore("ProcessingInstruction Found");
CError.WriteLineIgnore(reader.Name);
CError.WriteLineIgnore(">" + reader.Value + "<");
return false;
}
if (comm && _commentCount > 0)
{
CError.WriteLineIgnore("Comment Found");
CError.WriteLineIgnore(reader.Name);
CError.WriteLineIgnore(">" + reader.Value + "<");
return false;
}
if (ws && _wsCount > 0)
{
CError.WriteLineIgnore("Significant Whitespace Found");
CError.WriteLineIgnore(reader.Name);
CError.WriteLineIgnore(">" + reader.Value + "<");
return false;
}
return true;
}
开发者ID:noahfalk,项目名称:corefx,代码行数:48,代码来源:FilterSettings.cs
示例11: StartParsingAsync
public async Task StartParsingAsync(XmlReader reader, string targetNamespace)
{
_reader = reader;
_positionInfo = PositionInfo.GetPositionInfo(reader);
_namespaceManager = reader.NamespaceManager;
if (_namespaceManager == null)
{
_namespaceManager = new XmlNamespaceManager(_nameTable);
_isProcessNamespaces = true;
}
else
{
_isProcessNamespaces = false;
}
while (reader.NodeType != XmlNodeType.Element && await reader.ReadAsync().ConfigureAwait(false)) { }
_markupDepth = int.MaxValue;
_schemaXmlDepth = reader.Depth;
SchemaType rootType = _schemaNames.SchemaTypeFromRoot(reader.LocalName, reader.NamespaceURI);
string code;
if (!CheckSchemaRoot(rootType, out code))
{
throw new XmlSchemaException(code, reader.BaseURI, _positionInfo.LineNumber, _positionInfo.LinePosition);
}
if (_schemaType == SchemaType.XSD)
{
_schema = new XmlSchema();
_schema.BaseUri = new Uri(reader.BaseURI, UriKind.RelativeOrAbsolute);
_builder = new XsdBuilder(reader, _namespaceManager, _schema, _nameTable, _schemaNames, _eventHandler);
}
else
{
Debug.Assert(_schemaType == SchemaType.XDR);
_xdrSchema = new SchemaInfo();
_xdrSchema.SchemaType = SchemaType.XDR;
_builder = new XdrBuilder(reader, _namespaceManager, _xdrSchema, targetNamespace, _nameTable, _schemaNames, _eventHandler);
((XdrBuilder)_builder).XmlResolver = _xmlResolver;
}
}
开发者ID:Corillian,项目名称:corefx,代码行数:41,代码来源:ParserAsync.cs
示例12: CanDeserialize
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public virtual bool CanDeserialize(XmlReader xmlReader)
{
if (_primitiveType != null)
{
TypeDesc typeDesc = (TypeDesc)TypeScope.PrimtiveTypes[_primitiveType];
return xmlReader.IsStartElement(typeDesc.DataType.Name, string.Empty);
}
#if !NET_NATIVE
else if (_tempAssembly != null)
{
return _tempAssembly.CanRead(_mapping, xmlReader);
}
else
{
return false;
}
#else
if (this.innerSerializer != null)
{
return this.innerSerializer.CanDeserialize(xmlReader);
}
else
{
return ReflectionMethodEnabled;
}
#endif
}
开发者ID:SamuelEnglard,项目名称:corefx,代码行数:30,代码来源:XmlSerializer.cs
示例13: Deserialize
internal object Deserialize(XmlReader xmlReader, string encodingStyle, XmlDeserializationEvents events)
{
try
{
if (_primitiveType != null)
{
return DeserializePrimitive(xmlReader, events);
}
#if !NET_NATIVE
else if (Mode == SerializationMode.ReflectionOnly)
{
XmlMapping mapping;
if (_mapping.GenerateSerializer)
{
mapping = _mapping;
}
else
{
XmlReflectionImporter importer = new XmlReflectionImporter(DefaultNamespace);
mapping = importer.ImportTypeMapping(rootType, null, DefaultNamespace);
}
var reader = new ReflectionXmlSerializationReader(mapping, xmlReader, events, encodingStyle);
return reader.ReadObject();
}
else if (_tempAssembly == null || _typedSerializer)
{
XmlSerializationReader reader = CreateReader();
reader.Init(xmlReader, events, encodingStyle, _tempAssembly);
try
{
return Deserialize(reader);
}
finally
{
reader.Dispose();
}
}
else
{
return _tempAssembly.InvokeReader(_mapping, xmlReader, events, encodingStyle);
}
#else
else
{
if (this.innerSerializer != null)
{
if (!string.IsNullOrEmpty(this.DefaultNamespace))
{
this.innerSerializer.DefaultNamespace = this.DefaultNamespace;
}
XmlSerializationReader reader = this.innerSerializer.CreateReader();
reader.Init(xmlReader, encodingStyle);
try
{
return this.innerSerializer.Deserialize(reader);
}
finally
{
reader.Dispose();
}
}
else if (ReflectionMethodEnabled)
{
XmlMapping mapping;
if (_mapping != null && _mapping.GenerateSerializer)
{
mapping = _mapping;
}
else
{
XmlReflectionImporter importer = new XmlReflectionImporter(DefaultNamespace);
mapping = importer.ImportTypeMapping(rootType, null, DefaultNamespace);
}
var reader = new ReflectionXmlSerializationReader(mapping, xmlReader, events, encodingStyle);
return reader.ReadObject();
}
else
{
throw new InvalidOperationException(SR.Format(SR.Xml_MissingSerializationCodeException, this.rootType, typeof(XmlSerializer).Name));
}
}
#endif
}
catch (Exception e)
{
if (e is TargetInvocationException)
e = e.InnerException;
if (xmlReader is IXmlLineInfo)
{
IXmlLineInfo lineInfo = (IXmlLineInfo)xmlReader;
throw new InvalidOperationException(SR.Format(SR.XmlSerializeErrorDetails, lineInfo.LineNumber.ToString(CultureInfo.InvariantCulture), lineInfo.LinePosition.ToString(CultureInfo.InvariantCulture)), e);
}
else
{
throw new InvalidOperationException(SR.XmlSerializeError, e);
//.........这里部分代码省略.........
开发者ID:SamuelEnglard,项目名称:corefx,代码行数:101,代码来源:XmlSerializer.cs
示例14: Execute
/// <summary>
/// Executes the query by accessing datasources via the XmlResolver and using run-time parameters
/// as provided by the XsltArgumentList. The default document is mapped into the XmlResolver with the
/// provided name. The results are output to the provided Stream.
/// </summary>
public override void Execute(XmlReader contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, Stream results) {
if (results == null)
throw new ArgumentNullException(nameof(results));
Execute(contextDocument, dataSources, argumentList, XmlWriter.Create(results, this.staticData.DefaultWriterSettings), true);
}
开发者ID:geoffkizer,项目名称:corefx,代码行数:11,代码来源:XmlILCommand.cs
示例15: NestRead
private XmlReader NestRead(XmlReader r)
{
r.Read();
r.Read();
if (!(r.Name == "elem0" && r.NodeType == XmlNodeType.Element))
{
CError.WriteLine(r.Name);
NestRead(r.ReadSubtree());
}
r.Dispose();
return r;
}
开发者ID:noahfalk,项目名称:corefx,代码行数:12,代码来源:ReadSubTree.cs
示例16: DeserializePrimitive
private object DeserializePrimitive(XmlReader xmlReader, XmlDeserializationEvents events)
{
XmlSerializationPrimitiveReader reader = new XmlSerializationPrimitiveReader();
reader.Init(xmlReader, events, null, null);
object o;
switch (_primitiveType.GetTypeCode())
{
case TypeCode.String:
o = reader.Read_string();
break;
case TypeCode.Int32:
o = reader.Read_int();
break;
case TypeCode.Boolean:
o = reader.Read_boolean();
break;
case TypeCode.Int16:
o = reader.Read_short();
break;
case TypeCode.Int64:
o = reader.Read_long();
break;
case TypeCode.Single:
o = reader.Read_float();
break;
case TypeCode.Double:
o = reader.Read_double();
break;
case TypeCode.Decimal:
o = reader.Read_decimal();
break;
case TypeCode.DateTime:
o = reader.Read_dateTime();
break;
case TypeCode.Char:
o = reader.Read_char();
break;
case TypeCode.Byte:
o = reader.Read_unsignedByte();
break;
case TypeCode.SByte:
o = reader.Read_byte();
break;
case TypeCode.UInt16:
o = reader.Read_unsignedShort();
break;
case TypeCode.UInt32:
o = reader.Read_unsignedInt();
break;
case TypeCode.UInt64:
o = reader.Read_unsignedLong();
break;
default:
if (_primitiveType == typeof(XmlQualifiedName))
{
o = reader.Read_QName();
}
else if (_primitiveType == typeof(byte[]))
{
o = reader.Read_base64Binary();
}
else if (_primitiveType == typeof(Guid))
{
o = reader.Read_guid();
}
else if (_primitiveType == typeof(TimeSpan))
{
o = reader.Read_TimeSpan();
}
else
{
throw new InvalidOperationException(SR.Format(SR.XmlUnxpectedType, _primitiveType.FullName));
}
break;
}
return o;
}
开发者ID:SamuelEnglard,项目名称:corefx,代码行数:78,代码来源:XmlSerializer.cs
示例17: Test
/// <summary>
/// This method will test the read based on different settings.
/// It will call the correct overload and set the state properly.
/// </summary>
protected override void Test()
{
CError.WriteLine("Testing : " + TestFileName);
string tempStr = null;
switch (_overload)
{
case ReaderOverload.StreamReader:
_textReader = new StreamReader(FilePathUtil.getStream(GetFile(TestFileName)));
CreateReader(ReadThru.TextReader);
break;
case ReaderOverload.StringReader:
StreamReader sr = new StreamReader(FilePathUtil.getStream(GetFile(TestFileName)));
tempStr = sr.ReadToEnd();
sr.Dispose();
_textReader = new StringReader(tempStr);
CreateReader(ReadThru.TextReader);
break;
case ReaderOverload.FileStream:
_stream = FilePathUtil.getStream(TestFileName);
CreateReader(ReadThru.Stream);
break;
case ReaderOverload.MemoryStream:
StreamReader sr1 = new StreamReader(FilePathUtil.getStream(GetFile(TestFileName)));
tempStr = sr1.ReadToEnd();
sr1.Dispose();
byte[] bits = _enc.GetBytes(tempStr);
_stream = new MemoryStream(bits);
CreateReader(ReadThru.Stream);
break;
case ReaderOverload.CoreReader:
_underlyingSettings.DtdProcessing = DtdProcessing.Ignore;
_underlyingSettings.ConformanceLevel = _settings.ConformanceLevel;
StringReader strr = new StringReader(new StreamReader(FilePathUtil.getStream(GetFile(TestFileName))).ReadToEnd());
_underlyingReader = ReaderHelper.CreateReader(_overload.ToString(),
strr,
false,
null,
_underlyingSettings,
(_settings.ConformanceLevel == ConformanceLevel.Fragment)); //should this be settings or underlyingSettings?
CError.Compare(_underlyingReader != null, "ReaderHelper returned null Reader");
CreateReader(ReadThru.XmlReader);
break;
case ReaderOverload.CustomReader:
if (AsyncUtil.IsAsyncEnabled)
{
pstate = TestState.Skip;
return;
}
if (_settings.ConformanceLevel != ConformanceLevel.Fragment)
_underlyingReader = new CustomReader(FilePathUtil.getStream(GetFile(TestFileName)), false);
else
_underlyingReader = new CustomReader(FilePathUtil.getStream(GetFile(TestFileName)), true);
CError.Compare(_underlyingReader != null, "ReaderHelper returned null Reader");
CreateReader(ReadThru.XmlReader);
break;
default:
throw new CTestFailedException("Unknown ReaderOverload: " + _overload);
}
if (_underlyingReader != null)
CError.WriteLineIgnore("Type of Reader : " + _underlyingReader.GetType());
if (pstate == TestState.Pass) return;
CError.Compare(pstate, TestState.CreateSuccess, "Invalid State after Create: " + pstate);
//By this time the factory Reader is already set up correctly. So we must go Consume it now.
CError.Compare(pstate != TestState.Pass && pstate == TestState.CreateSuccess, "Invalid state before Consuming Reader: " + pstate);
//Call TestReader to Consume Reader;
TestReader();
if (pstate == TestState.Pass) return;
CError.Compare(pstate != TestState.Pass && pstate == TestState.Consume, "Invalid state after Consuming Reader: " + pstate);
}
开发者ID:er0dr1guez,项目名称:corefx,代码行数:84,代码来源:ReaderFactory.cs
示例18: CreateReader
/// <summary>
/// This method calls the Create Method on the XmlReader and puts the state in CreateSuccess or TestPass.
/// It goes in PASS also if the reader threw an expected error. In all other cases it should throw
/// TestFailedException.
/// </summary>
/// <param name="readThru">This param determines which overload to call.
/// In future on multiple overloads we can make this param
/// an enum which can be set using the spec file data</param>
protected void CreateReader(ReadThru readThru)
{
//Assumption is that the Create method doesnt throw NullReferenceException and
//it is not the goal of this framework to test if they are thrown anywhere.
//but if they are thrown thats a problem and they shouldnt be caught but exposed.
try
{
switch (readThru)
{
case ReadThru.TextReader:
_factoryReader = ReaderHelper.Create(_textReader, _settings, _baseUri);
break;
case ReadThru.XmlReader:
_factoryReader = ReaderHelper.Create(_underlyingReader, _settings);
break;
case ReadThru.Stream:
_factoryReader = ReaderHelper.Create(_stream, _settings);
break;
default:
throw new CTestFailedException("Unknown ReadThru type: " + readThru);
}
pstate = TestState.CreateSuccess;
}
catch (ArgumentNullException ane)
{
Log(ane.Message);
Log(ane.StackTrace);
if (!IsVariationValid)
{
if (!CheckException(ane))
{
pstate = TestState.Error;
DumpVariationInfo();
throw new CTestFailedException(
"Argument Null Exception Thrown in CreateMethod, is your variation data correct?");
}
else
{
//This means that the Exception was checked and everything is fine.
pstate = TestState.Pass;
}
}
else
{
pstate = TestState.Error;
DumpVariationInfo();
throw new CTestFailedException(
"Argument Null Exception Thrown in CreateMethod, is your variation data correct?");
}
}
}
开发者ID:er0dr1guez,项目名称:corefx,代码行数:60,代码来源:ReaderFactory.cs
示例19: Evaluate
/// <summary>
/// Executes the query by accessing datasources via the XmlResolver and using
/// run-time parameters as provided by the XsltArgumentList. The default document
/// is mapped into the XmlResolver with the provided name. The results are returned
/// as an IList.
/// </summary>
public override IList Evaluate(XmlReader contextDocument, XmlResolver dataSources, XsltArgumentList argumentList) {
XmlCachedSequenceWriter seqwrt = new XmlCachedSequenceWriter();
Execute(contextDocument, dataSources, argumentList, seqwrt);
return seqwrt.ResultSequence;
}
开发者ID:geoffkizer,项目名称:corefx,代码行数:11,代码来源:XmlILCommand.cs
示例20: Evaluate
/// <devdoc>
/// <para>
/// Executes the query by accessing datasources via the XmlResolver and using
/// run-time parameters as provided by the XsltArgumentList. The default document
/// is mapped into the XmlResolver with the provided name. The results are returned
/// as an IList.
/// </para>
/// </devdoc>
public abstract IList Evaluate(XmlReader contextDocument, XmlResolver dataSources, XsltArgumentList argumentList);
开发者ID:Corillian,项目名称:corefx,代码行数:9,代码来源:XmlCommand.cs
注:本文中的System.IO.XmlReader类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论