本文整理汇总了C#中System.Xml.XmlTextReader.Read方法的典型用法代码示例。如果您正苦于以下问题:C# System.Xml.XmlTextReader.Read方法的具体用法?C# System.Xml.XmlTextReader.Read怎么用?C# System.Xml.XmlTextReader.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlTextReader
的用法示例。
在下文中一共展示了System.Xml.XmlTextReader.Read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PhotoInfoParseFull
public void PhotoInfoParseFull()
{
string x = "<photo id=\"7519320006\">"
+ "<location latitude=\"54.971831\" longitude=\"-1.612683\" accuracy=\"16\" context=\"0\" place_id=\"Ke8IzXlQV79yxA\" woeid=\"15532\">"
+ "<neighbourhood place_id=\"Ke8IzXlQV79yxA\" woeid=\"15532\">Central</neighbourhood>"
+ "<locality place_id=\"DW0IUrFTUrO0FQ\" woeid=\"20928\">Gateshead</locality>"
+ "<county place_id=\"myqh27pQULzLWcg7Kg\" woeid=\"12602156\">Tyne and Wear</county>"
+ "<region place_id=\"2eIY2QFTVr_DwWZNLg\" woeid=\"24554868\">England</region>"
+ "<country place_id=\"cnffEpdTUb5v258BBA\" woeid=\"23424975\">United Kingdom</country>"
+ "</location>"
+ "</photo>";
System.IO.StringReader sr = new System.IO.StringReader(x);
System.Xml.XmlTextReader xr = new System.Xml.XmlTextReader(sr);
xr.Read();
var info = new PhotoInfo();
((IFlickrParsable)info).Load(xr);
Assert.AreEqual("7519320006", info.PhotoId);
Assert.IsNotNull(info.Location);
Assert.AreEqual((GeoAccuracy)16, info.Location.Accuracy);
Assert.IsNotNull(info.Location.Country);
Assert.AreEqual("cnffEpdTUb5v258BBA", info.Location.Country.PlaceId);
}
示例2: GetBytes
/// <summary>
/// Creates a byte array from the hexadecimal string. Each two characters are combined
/// to create one byte. First two hexadecimal characters become first byte in returned array.
/// Non-hexadecimal characters are ignored.
/// </summary>
/// <param name="hexString">string to convert to byte array</param>
/// <param name="discarded">number of characters in string ignored</param>
/// <returns>byte array, in the same left-to-right order as the hexString</returns>
public static byte[] GetBytes(string hexString, out int discarded)
{
discarded = 0;
// XML Reader/Writer is highly optimized for BinHex conversions
// use instead of byte/character replacement for performance on
// arrays larger than a few dozen elements
hexString = "<node>" + hexString + "</node>";
System.Xml.XmlTextReader tr = new System.Xml.XmlTextReader(
hexString,
System.Xml.XmlNodeType.Element,
null);
tr.Read();
System.IO.MemoryStream ms = new System.IO.MemoryStream();
int bufLen = 1024;
int cap = 0;
byte[] buf = new byte[bufLen];
do
{
cap = tr.ReadBinHex(buf, 0, bufLen);
ms.Write(buf, 0, cap);
} while (cap == bufLen);
return ms.ToArray();
}
示例3: IsolatedStorage_Read_and_Write_Sample
public static void IsolatedStorage_Read_and_Write_Sample()
{
string fileName = @"SelfWindow.xml";
IsolatedStorageFile storFile = IsolatedStorageFile.GetUserStoreForDomain();
IsolatedStorageFileStream storStream = new IsolatedStorageFileStream(fileName, FileMode.Create, FileAccess.Write);
System.Xml.XmlWriter writer = new System.Xml.XmlTextWriter(storStream, Encoding.UTF8);
writer.WriteStartDocument();
writer.WriteStartElement("Settings");
writer.WriteStartElement("UserID");
writer.WriteValue(42);
writer.WriteEndElement();
writer.WriteStartElement("UserName");
writer.WriteValue("kingwl");
writer.WriteEndElement();
writer.WriteEndElement();
writer.Flush();
writer.Close();
storStream.Close();
string[] userFiles = storFile.GetFileNames();
foreach(var userFile in userFiles)
{
if(userFile == fileName)
{
var storFileStreamnew = new IsolatedStorageFileStream(fileName,FileMode.Open,FileAccess.Read);
StreamReader storReader = new StreamReader(storFileStreamnew);
System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader(storReader);
int UserID = 0;
string UserName = null;
while(reader.Read())
{
switch(reader.Name)
{
case "UserID":
UserID = int.Parse(reader.ReadString());
break;
case "UserName":
UserName = reader.ReadString();
break;
default:
break;
}
}
Console.WriteLine("{0} {1}", UserID, UserName);
storFileStreamnew.Close();
}
}
storFile.Close();
}
示例4: Unmarshall
public override WebServiceResponse Unmarshall(XmlUnmarshallerContext context)
{
System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader(context.ResponseStream);
BatchReceiveMessageResponse batchReceiveMessageResponse = new BatchReceiveMessageResponse();
Message message = null;
while (reader.Read())
{
switch (reader.NodeType)
{
case System.Xml.XmlNodeType.Element:
switch (reader.LocalName)
{
case MNSConstants.XML_ROOT_MESSAGE:
message = new Message();
break;
case MNSConstants.XML_ELEMENT_MESSAGE_ID:
message.Id = reader.ReadElementContentAsString();
break;
case MNSConstants.XML_ELEMENT_RECEIPT_HANDLE:
message.ReceiptHandle = reader.ReadElementContentAsString();
break;
case MNSConstants.XML_ELEMENT_MESSAGE_BODY_MD5:
message.BodyMD5 = reader.ReadElementContentAsString();
break;
case MNSConstants.XML_ELEMENT_MESSAGE_BODY:
message.Body = reader.ReadElementContentAsString();
break;
case MNSConstants.XML_ELEMENT_ENQUEUE_TIME:
message.EnqueueTime = AliyunSDKUtils.ConvertFromUnixEpochSeconds(reader.ReadElementContentAsLong());
break;
case MNSConstants.XML_ELEMENT_NEXT_VISIBLE_TIME:
message.NextVisibleTime = AliyunSDKUtils.ConvertFromUnixEpochSeconds(reader.ReadElementContentAsLong());
break;
case MNSConstants.XML_ELEMENT_FIRST_DEQUEUE_TIME:
message.FirstDequeueTime = AliyunSDKUtils.ConvertFromUnixEpochSeconds(reader.ReadElementContentAsLong());
break;
case MNSConstants.XML_ELEMENT_DEQUEUE_COUNT:
message.DequeueCount = (uint)reader.ReadElementContentAsInt();
break;
case MNSConstants.XML_ELEMENT_PRIORITY:
message.Priority = (uint)reader.ReadElementContentAsInt();
break;
}
break;
case System.Xml.XmlNodeType.EndElement:
if (reader.LocalName == MNSConstants.XML_ROOT_MESSAGE)
{
batchReceiveMessageResponse.Messages.Add(message);
}
break;
}
}
reader.Close();
return batchReceiveMessageResponse;
}
示例5: GetSummary
/// <summary>
/// Currently a naive implementation. Treats all fields under summary as text.
/// </summary>
/// <param name="xmlDocumentation"></param>
/// <returns></returns>
public string GetSummary(string xmlDocumentation)
{
var frag = new System.Xml.XmlTextReader(xmlDocumentation, System.Xml.XmlNodeType.Element, null);
string result = "";
while (frag.Read()) {
result += frag.Value;
}
frag.Close();
return result;
}
示例6: ReadSettings
/// <summary>
/// loads a configuration from a xml-file - if there isn't one, use default settings
/// </summary>
public void ReadSettings()
{
bool dirty = false;
Reset();
try
{
System.Xml.XmlTextReader xmlConfigReader = new System.Xml.XmlTextReader("settings.xml");
while (xmlConfigReader.Read())
{
if (xmlConfigReader.NodeType == System.Xml.XmlNodeType.Element)
{
switch (xmlConfigReader.Name)
{
case "display":
fullscreen = Convert.ToBoolean(xmlConfigReader.GetAttribute("fullscreen"));
resolutionX = Convert.ToInt32(xmlConfigReader.GetAttribute("resolutionX"));
resolutionY = Convert.ToInt32(xmlConfigReader.GetAttribute("resolutionY"));
// validate resolution
// TODO
/* if (!GraphicsAdapter.DefaultAdapter.SupportedDisplayModes.Any(x => x.Format == SurfaceFormat.Color &&
x.Height == resolutionY && x.Width == resolutionX))
{
ChooseStandardResolution();
dirty = true;
} */
break;
}
}
}
xmlConfigReader.Close();
}
catch
{
// error in xml document - write a new one with standard values
try
{
Reset();
dirty = true;
}
catch
{
}
}
// override fullscreen resolutions
if (fullscreen)
{
ResolutionX = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width;
ResolutionY = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height;
}
if(dirty)
Save();
}
示例7: ReadConfig
// Lecture de la configuration
static void ReadConfig()
{
string config_file = "config.xml";
if (!System.IO.File.Exists(config_file))
{
var newconf = new System.Xml.XmlTextWriter(config_file, null);
newconf.WriteStartDocument();
newconf.WriteStartElement("config");
newconf.WriteElementString("last_update", "0");
newconf.WriteElementString("auth_token", "");
newconf.WriteEndElement();
newconf.WriteEndDocument();
newconf.Close();
}
var conf = new System.Xml.XmlTextReader(config_file);
string CurrentElement = "";
while (conf.Read())
{
switch(conf.NodeType) {
case System.Xml.XmlNodeType.Element:
CurrentElement = conf.Name;
break;
case System.Xml.XmlNodeType.Text:
if (CurrentElement == "last_update")
LastUpdate = DateTime.Parse(conf.Value);
if (CurrentElement == "auth_token")
AuthToken = conf.Value;
break;
}
}
conf.Close();
// On vérifie que le token est encore valide
if (AuthToken.Length > 0)
{
var flickr = new Flickr(Program.ApiKey, Program.SharedSecret);
try
{
Auth auth = flickr.AuthCheckToken(AuthToken);
Username = auth.User.UserName;
}
catch (FlickrApiException ex)
{
//MessageBox.Show(ex.Message, "Authentification requise",
// MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
AuthToken = "";
}
}
}
示例8: AppSettings
public AppSettings()
{
this.ProxySettings = new Proxy();
this.PathSettings = new PathSetting();
string proxySettingsFile = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\DichMusicHelperProxySettings.xml";
string pathSettingsFile = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\DichMusicHelperPathSettings.xml";
try
{
if (System.IO.File.Exists(proxySettingsFile))
{
using (System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader(proxySettingsFile))
{
while (reader.Read())
{
if (reader.Name == "ProxySettings")
{
this.ProxySettings.Server = reader[0];
this.ProxySettings.Port = reader[1];
this.ProxySettings.User = reader[2];
this.ProxySettings.Password = reader[3];
this.ProxySettings.UseProxy = Convert.ToBoolean(reader[4]);
}
}
}
}
if (System.IO.File.Exists(pathSettingsFile))
{
using (System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader(pathSettingsFile))
{
while (reader.Read())
{
if (reader.Name == "PathSettings")
{
this.PathSettings.Path = reader[0];
this.PathSettings.CreateFolder = Boolean.Parse(reader[1]);
}
}
}
}
}
catch (Exception)
{
}
}
示例9: LoadTemplate
public static int LoadTemplate(ref string err, ref DataSet rmdb, string file)
{
DataTable rmdb_set = new DataTable("fields");
rmdb_set.Columns.Add("id");
rmdb_set.Columns.Add("type");
rmdb_set.Columns.Add("value");
try {
System.Xml.XmlTextReader xmlReader = new System.Xml.XmlTextReader( file );
string contents = "";
while (xmlReader.Read()) {
xmlReader.MoveToContent();
string xmlId = null;
string xmlType = null;
string xmlValue = null;
if (xmlReader.NodeType == System.Xml.XmlNodeType.Element) {
// contents += "ELEMENT <"+xmlReader.Name + ">\n";
if (xmlReader.HasAttributes) {
// contents += "Attributes of <" + xmlReader.Name + ">\n";
for (int i = 0; i < xmlReader.AttributeCount; i++) {
// contents += xmlReader[i];
if (i == 0)
xmlId = xmlReader[i];
if (i == 1)
xmlType = xmlReader[i];
}
}
}
if (xmlReader.NodeType == System.Xml.XmlNodeType.Text) {
//contents += "TEXT " + xmlReader.Value + "\n";
xmlValue = xmlReader.Value;
}
// populate internal database
if (xmlId != null && xmlType != null) {
rmdb_set.Rows.Add(xmlId, xmlType, xmlValue);
Console.Write(xmlId, xmlType, xmlValue);
}
}
Console.Write(contents);
rmdb.Tables.Add(rmdb_set);
return 0;
}
catch (Exception e) {
err = e.Source.ToString() + ": " + e.Message.ToString();
return 1;
}
}
示例10: PhotoInfoLocationParseShortTest
public void PhotoInfoLocationParseShortTest()
{
string x = "<photo id=\"7519320006\">"
+ "<location latitude=\"-23.32\" longitude=\"-34.2\" accuracy=\"10\" context=\"1\" />"
+ "</photo>";
System.IO.StringReader sr = new System.IO.StringReader(x);
System.Xml.XmlTextReader xr = new System.Xml.XmlTextReader(sr);
xr.Read();
var info = new PhotoInfo();
((IFlickrParsable)info).Load(xr);
Assert.AreEqual("7519320006", info.PhotoId);
Assert.IsNotNull(info.Location);
Assert.AreEqual((GeoAccuracy)10, info.Location.Accuracy);
}
示例11: loadData
public static void loadData()
{
var file = "austria-latest.osm";
using (var fs = System.IO.File.OpenRead(file))
{
using (var xml = new System.Xml.XmlTextReader(fs))
{
while (xml.Read())
{
if (xml.NodeType == System.Xml.XmlNodeType.Element && xml.Name == "osm")
{
parseOsm(xml);
}
}
} // read from file
} // open from file
lastRefresh = DateTime.Now;
}
示例12: LoadConfig
public static int LoadConfig(ref string err, ref Hashtable settings, string file)
{
try {
System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader( file );
string contents = "";
while (reader.Read()) {
reader.MoveToContent();
if (reader.NodeType == System.Xml.XmlNodeType.Element)
contents += "<"+reader.Name + ">\n";
if (reader.NodeType == System.Xml.XmlNodeType.Text)
contents += reader.Value + "\n";
}
Console.Write(contents);
return 0;
}
catch (Exception e) {
err = e.Source.ToString() + ": " + e.Message.ToString();
return 1;
}
}
示例13: GetBuildStage
private string GetBuildStage()
{
if (!controller.SelectedProject.Detail.IsConnected)
{ return string.Empty; }
if (controller.SelectedProject.ProjectState != ProjectState.Building &&
controller.SelectedProject.ProjectState != ProjectState.BrokenAndBuilding)
{ return controller.SelectedProject.Detail.ProjectDescription; }
String currentBuildStage = controller.SelectedProject.Detail.CurrentBuildStage;
if (currentBuildStage == null || currentBuildStage.Length == 0)
{ return string.Empty; }
System.Text.StringBuilder SB = new System.Text.StringBuilder();
System.IO.StringWriter BuildStage = new System.IO.StringWriter(SB);
try
{
System.Xml.XmlTextReader XReader;
System.Xml.XmlDocument XDoc = new System.Xml.XmlDocument();
XDoc.LoadXml(controller.SelectedProject.Detail.CurrentBuildStage);
XReader = new System.Xml.XmlTextReader(XDoc.OuterXml, System.Xml.XmlNodeType.Document, null);
XReader.WhitespaceHandling = System.Xml.WhitespaceHandling.None;
while (XReader.Read())
{
XReader.MoveToContent();
if (XReader.AttributeCount > 0)
{
BuildStage.WriteLine("{0} {1}", XReader.GetAttribute("Time"), XReader.GetAttribute("Data"));
}
}
}
catch
{
BuildStage = new System.IO.StringWriter();
}
return BuildStage.ToString();
}
示例14: Read_Configuration_File
private void Read_Configuration_File(string config_file)
{
System.IO.StreamReader reader = new System.IO.StreamReader(config_file);
System.Xml.XmlTextReader xmlReader = new System.Xml.XmlTextReader(reader);
while (xmlReader.Read())
{
if (xmlReader.NodeType == System.Xml.XmlNodeType.Element)
{
string node_name = xmlReader.Name.ToLower();
switch (node_name)
{
case "connection_string":
if (xmlReader.MoveToAttribute("type"))
{
db_type = xmlReader.Value.ToString();
}
xmlReader.Read();
connection_string = xmlReader.Value;
break;
case "error_emails":
xmlReader.Read();
error_emails = xmlReader.Value;
break;
case "error_page":
xmlReader.Read();
error_page = xmlReader.Value;
break;
case "ghostscript_executable":
xmlReader.Read();
ghostscript = xmlReader.Value;
break;
case "imagemagick_executable":
xmlReader.Read();
imagemagick = xmlReader.Value;
break;
}
}
}
xmlReader.Close();
reader.Close();
}
示例15: listMetadataFormats
public ListMetadataFormats listMetadataFormats(string sidentifier)
{
System.IO.Stream objStream;
ListMetadataFormats objFormat = new ListMetadataFormats();
System.Net.HttpWebRequest wr;
System.Xml.XmlTextReader rd;
if (sidentifier.Length == 0)
{
prequestURL = baseURL + "?verb=ListMetadataFormats";
}
else
{
prequestURL = baseURL + "?verb=ListMetadataFormats&identifier=" + sidentifier;
}
try
{
wr = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(prequestURL);
wr.UserAgent = cUserAgent;
System.Net.WebResponse response = wr.GetResponse();
objStream = response.GetResponseStream();
System.IO.StreamReader reader = new System.IO.StreamReader(objStream);
prawXML = reader.ReadToEnd();
reader.Close();
rd = new System.Xml.XmlTextReader(prawXML, System.Xml.XmlNodeType.Document, null);
}
catch (Exception e)
{
error.errorName = e.ToString();
error.errorDescription = e.Message + "\n<br>Unable to connect to " + baseURL;
return null;
}
while (rd.Read())
{
if (rd.NodeType == System.Xml.XmlNodeType.Element)
{
if (rd.Name == "responseDate")
{
presponseDate = rd.ReadString();
}
else if (rd.Name == "ListMetadataFormats")
{
while (rd.Read()) // && rd.NodeType != System.Xml.XmlNodeType.EndElement)
{
switch (rd.Name)
{
case "metadataPrefix":
objFormat.metadataPrefix.Add(ParseOAI(ref rd, "metadataPrefix"));
break;
case "schema":
objFormat.schema.Add(ParseOAI(ref rd, "schema"));
break;
case "metadataNamespace":
objFormat.metadataNamespace.Add(ParseOAI(ref rd, "metadataNamespace"));
break;
default:
break;
}
}
}
else if (rd.Name == "error")
{
error.errorName = rd.GetAttribute("code");
error.errorDescription = rd.ReadString();
return null;
}
}
}
rd.Close();
return objFormat;
}