本文整理汇总了C#中System.Xml.XmlReader.Read方法的典型用法代码示例。如果您正苦于以下问题:C# XmlReader.Read方法的具体用法?C# XmlReader.Read怎么用?C# XmlReader.Read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlReader
的用法示例。
在下文中一共展示了XmlReader.Read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadFromXml
public void ReadFromXml(XmlReader reader)
{
reader.MoveToContent();
if (reader.IsEmptyElement) { reader.Read(); return; }
reader.Read();
while (!reader.EOF)
{
if (reader.IsStartElement())
{
if (reader.Name == "type")
{
var type = new ClassType();
type.ReadFromXml(reader);
classTypes.Add(type);
}
else
{
reader.Skip();
}
}
else
{
reader.Read();
break;
}
}
}
示例2: ExamQuestion
public ExamQuestion(XmlReader reader)
: this()
{
QuestionIdentifier = reader.GetAttribute("identifier");
Question = reader.GetAttribute("question");
Image = reader.GetAttribute("image");
while (!reader.EOF)
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
if (reader.Name == "Answer")
Answer = reader.ReadElementContentAsString();
else if (reader.Name == "Distractor")
Distractors.Add(reader.ReadElementContentAsString());
else
reader.Read();
break;
case XmlNodeType.EndElement:
return;
default:
reader.Read();
break;
}
}
}
示例3: ReadCurrentNode
internal XmlNode ReadCurrentNode(XmlDocument doc, XmlReader reader)
{
_doc = doc;
_reader = reader;
// WS are optional only for loading (see XmlDocument.PreserveWhitespace)
_preserveWhitespace = true;
if (doc == null)
throw new ArgumentException(SR.Xdom_Load_NoDocument);
if (reader == null)
throw new ArgumentException(SR.Xdom_Load_NoReader);
if (reader.ReadState == ReadState.Initial)
{
reader.Read();
}
if (reader.ReadState == ReadState.Interactive)
{
XmlNode n = LoadNode(true);
// Move to the next node
if (n.NodeType != XmlNodeType.Attribute)
reader.Read();
return n;
}
return null;
}
示例4: Task1
public string Task1()
{
reader = XmlReader.Create(FILE_NAME);
decimal in_v = 0;
decimal out_v = 0;
while (reader.Read())
{
if (reader.IsStartElement())
{
switch (reader.Name)
{
case IN_V:
if(reader.Read())
in_v += Convert.ToDecimal(reader.Value.Trim());
break;
case OUT_V:
if (reader.Read())
out_v += Convert.ToDecimal(reader.Value.Trim());
break;
}
}
}
reader.Close();
return IN_V + in_v.ToString() + "\n" + OUT_V + out_v.ToString();
}
示例5: Searchers
public Searchers(XmlReader reader)
{
this.Choices = new List<Choice>();
this.CurrentSearch = "";
reader.Read();
if (reader.Name != "TheSearchers")
return; // bail out
reader.Read();
while (!reader.EOF)
{
if ((reader.Name == "TheSearchers") && !reader.IsStartElement())
break; // all done
if (reader.Name == "Current")
this.CurrentSearch = reader.ReadElementContentAsString();
else if (reader.Name == "Choice")
{
string url = reader.GetAttribute("URL");
if (url == null)
url = reader.GetAttribute("URL2");
else
{
// old-style URL, replace "!" with "{ShowName}+{Season}+{Episode}"
url = url.Replace("!", "{ShowName}+{Season}+{Episode}");
}
this.Add(reader.GetAttribute("Name"), url);
reader.ReadElementContentAsString();
}
else
reader.ReadOuterXml();
}
}
示例6: readInFilepropertyElement
public void readInFilepropertyElement(XmlReader reader, string dotName, Fileproperty fileproperty)
{
//while (reader.NodeType != XmlNodeType.EndElement)
//{
reader.Read();//now on text node
if (reader.NodeType == XmlNodeType.Text)
{
//Console.WriteLine(dotName + " = " + reader.Value);
switch (dotName)
{
case "Name":
fileproperty.Filename = reader.Value;
reader.Read();//now on end element like </Name>
break;
case "StartingFrame":
fileproperty.StartingFrame = Convert.ToInt32(reader.Value);
reader.Read();//now on end element like </Name>
break;
case "TotalFrames":
fileproperty.TotalFrames = Convert.ToInt32(reader.Value);
reader.Read();//now on end element like </Name>
break;
}
}
//}
reader.Read();//now on the next start element like <StartingFrame>
}
示例7: ParseElement
/// <summary>
/// Parses the WDDX element and returns the deserialized
/// content as a <see cref="Hashtable"/> object, advancing the reader to the next
/// element.
/// </summary>
/// <param name="input">The pre-initialized <see cref="System.Xml.XmlTextReader"/> pointing to the WDDX to be parsed.</param>
public object ParseElement(XmlReader input)
{
Hashtable thisTable = new Hashtable();
if (input.IsEmptyElement)
{
input.Skip();
return thisTable;
}
string elementName;
object elementValue;
IWddxElementDeserializer deserializer;
while (input.Read() && (!(input.Name == "struct" && input.NodeType == XmlNodeType.EndElement)))
{
if (input.Name == "var" && input.NodeType != XmlNodeType.EndElement)
{
elementName = input.GetAttribute("name");
input.Read(); // move to contents of <var>
deserializer = WddxElementDeserializerFactory.GetDeserializer(input.Name);
elementValue = deserializer.ParseElement(input);
thisTable.Add(elementName, elementValue);
}
}
input.ReadEndElement();
return thisTable;
}
示例8: ReadXml
public void ReadXml(XmlReader reader)
{
//goto inner hidden
reader.Read();
Text = reader.ReadInnerXml();
reader.Read();
}
示例9: while
void IFlickrParsable.Load(XmlReader reader)
{
reader.Read();
while (reader.LocalName != "photos")
{
switch (reader.LocalName)
{
case "firstdatetaken":
this.FirstTakenDate = UtilityMethods.ParseDateWithGranularity(reader.ReadElementContentAsString());
continue;
case "firstdate":
this.FirstDate = UtilityMethods.UnixTimestampToDate(reader.ReadElementContentAsString());
continue;
case "count":
this.PhotoCount = reader.ReadElementContentAsInt();
continue;
case "views":
this.Views = reader.ReadElementContentAsInt();
continue;
default:
reader.Skip();
continue;
}
}
reader.Read();
}
示例10: NoExtensionsSetup
void NoExtensionsSetup ()
{
XmlReaderSettings xs = new XmlReaderSettings ();
xs.IgnoreWhitespace = true;
xtr = XmlTextReader.Create ("Test/System.ServiceModel.Description/dump.xml", xs);
xtr.Read ();
//FIXME: skipping Headers
while (xtr.LocalName != "Body") {
if (!xtr.Read ())
return;
}
//Move to <Metadata ..
xtr.Read ();
ms = MetadataSet.ReadFrom (xtr);
//MyWsdlImportExtension mw = new MyWsdlImportExtension ();
List<IWsdlImportExtension> list = new List<IWsdlImportExtension> ();
//list.Add (mw);
list.Add (new DataContractSerializerMessageContractImporter ());
/*list.Add (new MessageEncodingBindingElementImporter ());
list.Add (new TransportBindingElementImporter ());
list.Add (new StandardBindingImporter ());*/
wi = new WsdlImporter (ms, null, list);
}
示例11: Deserialise
public static void Deserialise(this PageInfo pageInfo, XmlReader reader)
{
if (reader.NodeType == XmlNodeType.Element && reader.Name.Equals("PageInfo"))
{
while (reader.Read() && reader.NodeType == XmlNodeType.Element)
{
string elementName = reader.Name;
if (reader.Read() && reader.NodeType == XmlNodeType.Text)
{
int value;
if (int.TryParse(reader.Value, out value))
{
switch (elementName)
{
case "TotalCount":
pageInfo.TotalCount = value;
break;
case "ItemsCount":
pageInfo.ItemsCount = value;
break;
case "StartIndex":
pageInfo.StartIndex = value;
break;
}
}
}
reader.Read(); // end element
}
}
}
示例12: ReadFromXml
public void ReadFromXml(XmlReader reader)
{
reader.MoveToContent();
if (reader.IsEmptyElement) { reader.Read(); return; }
reader.Read();
while (!reader.EOF)
{
if (reader.IsStartElement())
{
if (reader.Name == "module")
{
var module = new Module();
module.ReadFromXml(reader);
modules.Add(module);
}
else
{
reader.Skip();
}
}
else
{
reader.Read();
break;
}
}
}
示例13: while
void IFlickrParsable.Load(XmlReader reader)
{
while (reader.MoveToNextAttribute())
{
switch (reader.LocalName)
{
case "usage":
Usage = reader.ReadContentAsInt();
break;
case "predicate":
PredicateName = reader.Value;
break;
case "namespace":
NamespaceName = reader.Value;
break;
}
}
reader.Read();
if (reader.NodeType == XmlNodeType.Text)
PairName = reader.ReadContentAsString();
reader.Read();
}
示例14: ReadTerrain
private void ReadTerrain(XmlReader reader, string key)
{
Terrain terrain = new Terrain (key);
while (reader.Read ()) {
if ((reader.NodeType == XmlNodeType.EndElement) &&
(reader.Name == "terrain"))
break;
if (reader.NodeType != XmlNodeType.Element)
continue;
string element = reader.Name;
reader.Read ();
if (element == "name")
terrain.Name = reader.Value;
else if (element == "description")
terrain.Description = reader.Value;
else if (element == "blocks")
terrain.IsBlocking = Boolean.Parse (reader.Value);
else if (element == "tile")
terrain.Tiles.Add (reader.Value);
}
if (!terrain.IsValid)
throw new ApplicationException (String.Format
("Terrain '{0}' is missing a child element.",
key));
terrains.Add (key, terrain);
}
示例15: GetFeed
public static IFeed GetFeed(Uri url, XmlReader reader) {
reader.MoveToContent();
string language = string.Empty;
FeedType feedType;
string namespaceUri = reader.NamespaceURI;
if(reader.LocalName.Equals("RDF") &&
reader.NamespaceURI.Equals("http://www.w3.org/1999/02/22-rdf-syntax-ns#")) {
feedType = FeedType.Rdf;
reader.Read();
reader.MoveToContent();
} else if(reader.LocalName.Equals("rss")) {
feedType = FeedType.Rss;
do {
reader.Read();
reader.MoveToContent();
} while(!reader.LocalName.Equals("channel") && !reader.LocalName.Equals("rss"));
} else if(reader.NamespaceURI.Equals("http://purl.org/atom/ns#") && reader.LocalName.Equals("feed")) {
if(reader.MoveToAttribute("version") && reader.Value.Equals("0.3")) {
feedType = FeedType.Atom;
language = reader.XmlLang;
reader.MoveToElement();
} else {
throw new ApplicationException(string.Format("Unsupported Atom Version {0}", reader.Value));
}
} else if(reader.NamespaceURI.Equals("http://www.w3.org/2005/Atom") && reader.LocalName.Equals("feed")) {
feedType = FeedType.Atom;
language = reader.XmlLang;
} else {
throw new ApplicationException("Unknown Xml Dialect");
}
return PopulateFeed(url, reader, namespaceUri, feedType, language);
}