本文整理汇总了C#中XmlReader类的典型用法代码示例。如果您正苦于以下问题:C# XmlReader类的具体用法?C# XmlReader怎么用?C# XmlReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XmlReader类属于命名空间,在下文中一共展示了XmlReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AssertNodeValues
private void AssertNodeValues (
XmlReader xmlReader,
XmlNodeType nodeType,
int depth,
bool isEmptyElement,
string name,
string prefix,
string localName,
string namespaceURI,
string value,
int attributeCount)
{
Assert.AreEqual (nodeType, xmlReader.NodeType, "NodeType");
Assert.AreEqual (depth, xmlReader.Depth, "Depth");
Assert.AreEqual (isEmptyElement, xmlReader.IsEmptyElement, "IsEmptyElement");
Assert.AreEqual (name, xmlReader.Name, "name");
Assert.AreEqual (prefix, xmlReader.Prefix, "prefix");
Assert.AreEqual (localName, xmlReader.LocalName, "localName");
Assert.AreEqual (namespaceURI, xmlReader.NamespaceURI, "namespaceURI");
Assert.AreEqual ((value != String.Empty), xmlReader.HasValue, "hasValue");
Assert.AreEqual (value, xmlReader.Value, "Value");
Assert.AreEqual (attributeCount > 0, xmlReader.HasAttributes, "hasAttributes");
Assert.AreEqual (attributeCount, xmlReader.AttributeCount, "attributeCount");
}
示例2: GetMemberElement
private static string GetMemberElement(
FunctionDescriptor function,
XmlReader xml,
DocumentElementType property,
string paramName = "")
{
//customNodeDefinitions typedParameters don't have functionDescriptors
if (function == null)
{
return string.Empty;
}
var assemblyName = function.Assembly;
if (string.IsNullOrEmpty(assemblyName))
return String.Empty;
var fullyQualifiedName = MemberDocumentNode.MakeFullyQualifiedName
(assemblyName, GetMemberElementName(function));
if (!documentNodes.ContainsKey(fullyQualifiedName))
{
if (xml == null)
xml = DocumentationServices.GetForAssembly(function.Assembly, function.PathManager);
LoadDataFromXml(xml, assemblyName);
}
MemberDocumentNode documentNode = null;
if (documentNodes.ContainsKey(fullyQualifiedName))
documentNode = documentNodes[fullyQualifiedName];
else
{
var overloadedName = documentNodes.Keys.
Where(key => key.Contains(function.ClassName + "." + function.FunctionName)).FirstOrDefault();
if (overloadedName == null)
return String.Empty;
if (documentNodes.ContainsKey(overloadedName))
documentNode = documentNodes[overloadedName];
}
if (documentNode == null)
return String.Empty;
if (property.Equals(DocumentElementType.Description) && !documentNode.Parameters.ContainsKey(paramName))
return String.Empty;
switch (property)
{
case DocumentElementType.Summary:
return documentNode.Summary;
case DocumentElementType.Description:
return documentNode.Parameters[paramName];
case DocumentElementType.SearchTags:
return documentNode.SearchTags;
default:
throw new ArgumentException("property");
}
}
示例3: client_DownloadStringCompleted
private void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
int itemsCount = 7;
xmlReader = XmlReader.Create(new StringReader(e.Result));
feed = SyndicationFeed.Load(xmlReader);
List<RSSItem> itemsList = new List<RSSItem>();
if (feed.Items.Count() < 7)
{
itemsCount = feed.Items.Count();
}
for (int i = 0; i <= itemsCount; i++)
{
RSSItem rssitem = new RSSItem();
rssitem.RSSTitle = feed.Items.ToList()[i].Title.Text;
rssitem.RSSLink = feed.Items.ToList()[i].Links[0].Uri;
itemsList.Add(rssitem);
}
RSS.ItemsSource = itemsList;
}
}
示例4: DnaXmlValidator
/// <summary>
/// Constructor
/// </summary>
/// <param name="xml">XML to validate</param>
/// <param name="schemaUri">Schema Uri</param>
public DnaXmlValidator(string xml, string schemaUri)
{
_schemaUri = schemaUri;
// set up the schema
LoadSchema(schemaUri);
// set up the xml reader
_rawXml = xml;
_xml = new StringReader(xml);
// set up the settings for validating the xml
_validationSettings = new XmlReaderSettings();
_validationSettings.Schemas.Add(_xmlSchema);
_validationSettings.IgnoreWhitespace = true;
_validationSettings.ValidationFlags |= XmlSchemaValidationFlags.ProcessSchemaLocation;
_validationSettings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings;
_validationSettings.ValidationFlags |= XmlSchemaValidationFlags.ProcessInlineSchema;
_validationSettings.ValidationType = ValidationType.Schema;
try
{
_validationSettings.Schemas.Compile();
}
catch (XmlSchemaException e)
{
string s = e.SourceUri;
}
_validationSettings.ValidationEventHandler += new ValidationEventHandler(xmlReaderSettingsValidationEventHandler);
_validationSettings.DtdProcessing = DtdProcessing.Parse;
// set the the XmlReader for validation
_validator = XmlReader.Create(_xml, _validationSettings);
}
示例5: CanRead
public override bool CanRead (XmlReader reader)
{
if (reader == null)
throw new ArgumentNullException ("reader");
reader.MoveToContent ();
return reader.LocalName == "service" && reader.NamespaceURI == Version;
}
示例6: createPlayer
void createPlayer(XmlReader reader)
{
Vector2 pos = Vector2.Zero;
TextureMap t = new TextureMap();
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
switch (reader.Name)
{
case "position":
{
reader.ReadToDescendant("x");
float x = (float)float.Parse((reader.GetAttribute(0)));
reader.ReadToNextSibling("y");
float y = (float)float.Parse((reader.GetAttribute(0)));
pos = new Vector2(x, y);
}
break;
default:
int o = 0;//fer teh deboog
break;
}
}
}
Player p = new Player(pos, t);
}
示例7: AssertStartDocument
// copy from XmlTextReaderTests
private void AssertStartDocument (XmlReader xmlReader)
{
Assert.IsTrue (xmlReader.ReadState == ReadState.Initial);
Assert.IsTrue (xmlReader.NodeType == XmlNodeType.None);
Assert.IsTrue (xmlReader.Depth == 0);
Assert.IsTrue (!xmlReader.EOF);
}
示例8: AssertNodeValues
private void AssertNodeValues (
XmlReader xmlReader,
XmlNodeType nodeType,
int depth,
bool isEmptyElement,
string name,
string prefix,
string localName,
string namespaceURI,
string value,
int attributeCount)
{
AssertEquals ("NodeType", nodeType, xmlReader.NodeType);
AssertEquals ("Depth", depth, xmlReader.Depth);
AssertEquals ("IsEmptyElement", isEmptyElement, xmlReader.IsEmptyElement);
AssertEquals ("name", name, xmlReader.Name);
AssertEquals ("prefix", prefix, xmlReader.Prefix);
AssertEquals ("localName", localName, xmlReader.LocalName);
AssertEquals ("namespaceURI", namespaceURI, xmlReader.NamespaceURI);
AssertEquals ("hasValue", (value != String.Empty), xmlReader.HasValue);
AssertEquals ("Value", value, xmlReader.Value);
AssertEquals ("hasAttributes", attributeCount > 0, xmlReader.HasAttributes);
AssertEquals ("attributeCount", attributeCount, xmlReader.AttributeCount);
}
示例9: ValidateXml
public static bool ValidateXml(XmlReader reader, string customSchema, Action<string> warning, Action<string> error)
{
bool isValid = true;
var schemas = GetSchemas();
if (customSchema != null)
{
schemas.Add(null, XmlReader.Create(customSchema));
}
ValidationEventHandler handler = (s, args) =>
{
isValid = false;
if (warning != null && args.Severity == XmlSeverityType.Warning)
warning(args.Message);
else if (error != null)
error(args.Message);
};
var settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas.Add(schemas);
settings.ValidationEventHandler += handler;
var r = XmlReader.Create(reader, settings);
while (r.Read()) ;
return isValid;
}
示例10: ClientData
private ClientData(XmlReader reader)
{
reader.ReadStartElement("ClientData");
for (int iter = 0; iter < _NumStoredValues; iter++) {
reader.ReadStartElement(_StoredValueNames[iter]);
if (_StoredValues[iter] is string)
_StoredValues[iter] = reader.ReadContentAsString();
else if (_StoredValues[iter] is DateTime) {
string s = reader.ReadContentAsString();
long l = long.Parse(s, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
_StoredValues[iter] = DateTime.FromFileTimeUtc(l);
} else if (_StoredValues[iter] is bool) {
string s = reader.ReadContentAsString();
_StoredValues[iter] = !(string.IsNullOrEmpty(s) || s != "1");
} else {
_StoredValues[iter] = ReadStringArray(reader);
}
reader.ReadEndElement();
}
reader.ReadEndElement();
}
示例11: LoadFromXml
public void LoadFromXml (XmlReader reader)
{
reader.ReadToDescendant ("plist");
while (reader.Read () && reader.NodeType != XmlNodeType.Element);
if (!reader.EOF)
root = LoadFromNode (reader);
}
示例12: ParseCategories
/// <summary>tries to parse a category collection document</summary>
/// <param name="reader"> xmlReader positioned at the start element</param>
/// <param name="owner">the base object that the collection belongs to</param>
/// <returns></returns>
public AtomCategoryCollection ParseCategories(XmlReader reader, AtomBase owner) {
Tracing.Assert(reader != null, "reader should not be null");
if (reader == null) {
throw new ArgumentNullException("reader");
}
AtomCategoryCollection ret = new AtomCategoryCollection();
MoveToStartElement(reader);
Tracing.TraceCall("entering Categories Parser");
object localname = reader.LocalName;
Tracing.TraceInfo("localname is: " + reader.LocalName);
if (IsCurrentNameSpace(reader, BaseNameTable.AppPublishingNamespace(owner)) &&
localname.Equals(this.nameTable.Categories)) {
Tracing.TraceInfo("Found categories document");
int depth = -1;
while (NextChildElement(reader, ref depth)) {
localname = reader.LocalName;
if (IsCurrentNameSpace(reader, BaseNameTable.NSAtom)) {
if (localname.Equals(this.nameTable.Category)) {
AtomCategory category = ParseCategory(reader, owner);
ret.Add(category);
}
}
}
} else {
Tracing.TraceInfo("ParseCategories called and nothing was parsed" + localname);
throw new ClientFeedException("An invalid Atom Document was passed to the parser. This was not an app:categories document: " + localname);
}
return ret;
}
示例13: GenerateCode
private static string GenerateCode(XmlReader reader, string nameSpace)
{
EntityClassGenerator generator = new EntityClassGenerator(LanguageOption.GenerateCSharpCode) {
Version = DataServiceCodeVersion.V2
};
StringWriter targetWriter = new StringWriter();
try
{
IList<EdmSchemaError> list = generator.GenerateCode(reader, targetWriter, nameSpace);
if (list.Count > 0)
{
throw new DisplayToUserException(string.Concat(new object[] { "Bad schema: ", list[0].Message, " (line ", list[0].Line, ")" }));
}
}
catch (MetadataException exception)
{
throw new DisplayToUserException("MetadataException: " + exception.Message);
}
catch (XmlSchemaValidationException exception2)
{
throw new DisplayToUserException("This schema is unsupported.\r\n\r\nEntityClassGenerator returned the following error: " + exception2.Message);
}
catch (FileNotFoundException exception3)
{
if (exception3.Message.Contains("System.Data.Services.Design"))
{
throw new DisplayToUserException("Cannot load System.Data.Services.Design.dll. (A possible cause is installing only the .NET Framework Client Profile instead of the full .NET Framework.)");
}
throw;
}
return targetWriter.ToString();
}
示例14: DeserializeResponse
public XmlRpcResponse DeserializeResponse(XmlReader rdr, Type returnType)
{
try
{
IEnumerator<Node> enumerator = new XmlRpcParser().ParseResponse(rdr).GetEnumerator();
enumerator.MoveNext();
if (enumerator.Current is FaultNode)
throw DeserializeFault(enumerator);
if (returnType == typeof (void) || !enumerator.MoveNext())
{
return new XmlRpcResponse
{
retVal = null
};
}
Node current = enumerator.Current;
object obj = MapValueNode(enumerator, returnType, new MappingStack("response"), MappingAction.Error);
return new XmlRpcResponse
{
retVal = obj
};
}
catch (XmlException ex)
{
throw new XmlRpcIllFormedXmlException("Response contains invalid XML", ex);
}
}
示例15: DeserializeElement
protected override void DeserializeElement(XmlReader reader, bool serializeCollectionKey)
{
base.DeserializeElement(reader, serializeCollectionKey);
WebContext hostingContext = base.EvaluationContext.HostingContext as WebContext;
if ((hostingContext != null) && (this.Href.Length != 0))
{
string path = hostingContext.Path;
string configurationDirectory = null;
if (path == null)
{
path = HostingEnvironment.ApplicationVirtualPath;
if (path == null)
{
path = "";
}
configurationDirectory = this.GetConfigurationDirectory();
}
else
{
configurationDirectory = HostingEnvironment.MapPath(path);
}
if (!path.EndsWith("/", StringComparison.Ordinal))
{
path = path + "/";
}
CheckIOReadPermission(configurationDirectory, this.Href);
this.actualPath = configurationDirectory;
this.virtualPath = path;
this.needToValidateHref = true;
}
}