本文整理匯總了C#中System.Xml.XmlTextReader.Close方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlTextReader.Close方法的具體用法?C# XmlTextReader.Close怎麽用?C# XmlTextReader.Close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.XmlTextReader
的用法示例。
在下文中一共展示了XmlTextReader.Close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: getEntry
public string getEntry(string pathToXML, string entryToLook)
{
XmlTextReader reader = new XmlTextReader (pathToXML);
string tmpStr = "";
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
tmpStr = reader.Name;
break;
case XmlNodeType.Text: /* Display the text in each element. */
if (tmpStr == entryToLook)
{
tmpStr = reader.Value;
reader.Close();
return tmpStr;
}
break;
/* No needed, just example */
/* case XmlNodeType.EndElement: //Display the end of the element.
* Console.Write("</" + reader.Name);
* Console.WriteLine(">");
* break;
*/
}
}
reader.Close();
return null;
/* Console.ReadLine(); */
}
示例2: CreateDocumentFromFile
public static SvgDocument CreateDocumentFromFile(string filename)
{
Stream stream1 = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
SvgDocument document1 = new SvgDocument();
XmlTextReader reader1 = new XmlTextReader(stream1, XmlNodeType.Document, document1.XmlParserContext);
try
{
reader1.XmlResolver = null;
document1.PreserveWhitespace = true;
document1.XmlResolver = null;
document1.FilePath = filename;
document1.Load(reader1);
//document1.DealLast();
reader1.Close();
stream1.Close();
document1.FileName = Path.GetFileNameWithoutExtension(filename);
document1.Update = true;
return document1;
}
catch (Exception exception1)
{
reader1.Close();
stream1.Close();
MessageBox.Show("���Ϸ��ĵ���" + exception1.Message);
}
return null;
}
示例3: LoadSounds
public void LoadSounds()
{
if (File.Exists(soundsFile))
{
XmlTextReader textReader = null;
try
{
XmlSerializer deserializer = new XmlSerializer(typeof(IceChatSounds));
textReader = new XmlTextReader(soundsFile);
iceChatSounds = (IceChatSounds)deserializer.Deserialize(textReader);
textReader.Close();
}
catch (Exception)
{
textReader.Close();
errorMessages.Add("There was a problem loading IceChatSounds.xml. Default sounds loaded");
iceChatSounds = new IceChatSounds();
iceChatSounds.AddDefaultSounds();
}
}
else
{
iceChatSounds = new IceChatSounds();
iceChatSounds.AddDefaultSounds();
}
}
示例4: CategoriesInfoRepository
public CategoriesInfoRepository()
{
XmlReader reader = new XmlTextReader(path);
List<CategoryInfo> infoFromXml = (List<CategoryInfo>)writers.Deserialize(reader);
reader.Close();
this.categoriesInfolList = infoFromXml;
}
示例5: Load
/// <summary>
/// Load matrix from XML file
/// </summary>
/// <param name="fileName">file name</param>
/// <returns>Loaded matrix</returns>
public Matrix Load(string fileName)
{
XmlTextReader textReader = new XmlTextReader(fileName);
Matrix matrix = new Matrix();
string fromWord = null;
string toWord;
float statisticValue;
while (textReader.Read())
{
if (textReader.NodeType == XmlNodeType.Element)
{
if (textReader.Name == "fromWord")
{
fromWord = textReader.GetAttribute("name");
}
else if (textReader.Name == "toWord")
{
if (fromWord != null)
{
toWord = textReader.GetAttribute("name");
float.TryParse(textReader.GetAttribute("statisticValue"), out statisticValue);
matrix.SetStatistics(fromWord, toWord, statisticValue);
}
}
}
}
textReader.Close();
return matrix;
}
示例6: visualizeDo_Click
protected void visualizeDo_Click(object sender, EventArgs e)
{
// get xslt file
string xslt = "";
if (xsltSelection.Value.Contains("<xsl:stylesheet"))
{
xslt = xsltSelection.Value;
}
else
{
System.IO.StreamReader xsltFile =
System.IO.File.OpenText(
IOHelper.MapPath(SystemDirectories.Umbraco + "/xslt/templates/clean.xslt")
);
xslt = xsltFile.ReadToEnd();
xsltFile.Close();
// parse xslt
xslt = xslt.Replace("<!-- start writing XSLT -->", xsltSelection.Value);
// prepare support for XSLT extensions
xslt = macro.AddXsltExtensionsToHeader(xslt);
}
Dictionary<string, object> parameters = new Dictionary<string, object>(1);
parameters.Add("currentPage", library.GetXmlNodeById(contentPicker.Value));
// apply the XSLT transformation
string xsltResult = "";
XmlTextReader xslReader = null;
try
{
xslReader = new XmlTextReader(new StringReader(xslt));
System.Xml.Xsl.XslCompiledTransform xsl = macro.CreateXsltTransform(xslReader, false);
xsltResult = macro.GetXsltTransformResult(new XmlDocument(), xsl, parameters);
}
catch (Exception ee)
{
xsltResult = string.Format(
"<div class=\"error\"><h3>Error parsing the XSLT:</h3><p>{0}</p></div>",
ee.ToString());
}
finally
{
xslReader.Close();
}
visualizeContainer.Visible = true;
// update output
visualizeArea.Text = !String.IsNullOrEmpty(xsltResult) ? "<div id=\"result\">" + xsltResult + "</Div>" : "<div class=\"notice\"><p>The XSLT didn't generate any output</p></div>";
// add cookie with current page
// zb-00004 #29956 : refactor cookies names & handling
cookie.SetValue(contentPicker.Value);
}
示例7: GetSchema
public static XmlSchema GetSchema (string path)
{
XmlTextReader reader = new XmlTextReader (path);
XmlSchema schema = XmlSchema.Read (reader, null);
reader.Close ();
return schema;
}
示例8: Table_GetAll
public List<object> Table_GetAll()
{
var returnValue = new List<object>();
try
{
var allTables = base.GetAllFiles(this._tableDirectoryPath);
foreach (var table in allTables)
{
var fileStream = base.GetFileReadStream(table.Value);
var xmlTextReader = new XmlTextReader(fileStream);
returnValue.Add(Serializer.Deserialize(xmlTextReader));
fileStream.Close();
fileStream.Dispose();
xmlTextReader.Close();
xmlTextReader.Dispose();
}
}
catch (Exception ex)
{
if (this._logger != null)
{
this._logger.Log(ex.Message, Category.Exception, Priority.High);
}
}
return returnValue;
}
示例9: LoadFromXmlFile
public void LoadFromXmlFile(string sFile)
{
Clear();
XmlTextReader xr = new XmlTextReader(sFile);
while (xr.Read())
{
if (xr.NodeType == XmlNodeType.Element)
{
if (xr.Name == "FontValidatorProject")
{
m_sComputerName = xr.GetAttribute("MachineName");
}
else if (xr.Name == "FontFile")
{
string sPath = xr.GetAttribute("Path");
m_sFilesToTest.Add(sPath);
}
else if (xr.Name == "Test")
{
string sTableName = xr.GetAttribute("Name");
string sValue = xr.GetAttribute("Value");
bool bTest = true;
if (sValue.ToLower().CompareTo("true") != 0)
{
bTest = false;
}
m_hashTestsToPerform[sTableName] = bTest;
}
}
}
xr.Close();
m_sFilename = sFile;
}
示例10: LoadData
public void LoadData()
{
lock (this)
{
doc = new XmlDocument();
if (File.Exists(fileName))
{
XmlTextReader reader = new XmlTextReader(fileName);
reader.WhitespaceHandling = WhitespaceHandling.None;
doc.Load(reader);
reader.Close();
}
else
{
createdFile = true;
rootNode = doc.CreateNode(XmlNodeType.Element, "Root", String.Empty);
doc.AppendChild(rootNode);
configNode = doc.CreateNode(XmlNodeType.Element, "Config", String.Empty);
rootNode.AppendChild(configNode);
}
LoadDataToClass();
if (createdFile)
{
Commit();
}
}
}
示例11: Deserialize
/// <summary>
/// Deserializes an xml document back into an object
/// </summary>
/// <param name="xml">The xml data to deserialize</param>
/// <param name="type">The type of the object being deserialized</param>
/// <returns>A deserialized object</returns>
public static object Deserialize(XmlDocument xml, Type type)
{
XmlSerializer s = new XmlSerializer(type);
string xmlString = xml.OuterXml.ToString();
byte[] buffer = ASCIIEncoding.UTF8.GetBytes(xmlString);
MemoryStream ms = new MemoryStream(buffer);
XmlReader reader = new XmlTextReader(ms);
Exception caught = null;
try
{
object o = s.Deserialize(reader);
return o;
}
catch (Exception e)
{
caught = e;
}
finally
{
reader.Close();
if (caught != null)
throw caught;
}
return null;
}
示例12: ReadConfigFile
public void ReadConfigFile(String settingsFile, ref List<String> dataLocations, ref List<String> providers)
{
//clear providers variable from form1 so that we dont havea huge list with duplicates
providers.Clear();
XmlTextReader reader = new XmlTextReader(settingsFile);
String previousNodeName = "";
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element: // this node is an element
break;
case XmlNodeType.Text: //display the text in each element
if (previousNodeName == "MetricsFolder")
{
dataLocations.Add(reader.Value);
}
if (previousNodeName == "DashboardFile")
{
dataLocations.Add(reader.Value);
}
if (previousNodeName == "Name")
{
providers.Add(reader.Value);
}
break;
case XmlNodeType.EndElement: //display the end of the element
break;
}
previousNodeName = reader.Name;
}
reader.Close();
}
示例13: GetIssueListFromXmlStream
public static List<Issue> GetIssueListFromXmlStream(Stream stream) {
List<Issue> issues = new List<Issue>();
XmlTextReader reader = new XmlTextReader(stream);
XmlDocument doc = new XmlDocument();
doc.Load(reader);
reader.Close();
XmlNodeList list = doc.DocumentElement.GetElementsByTagName("item");
XmlSerializer s = new XmlSerializer(typeof(Issue));
//Create the XmlNamespaceManager.
NameTable nt = new NameTable();
XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);
nsmgr.AddNamespace("jc", "urn:jiraconn");
//Create the XmlParserContext.
XmlParserContext context = new XmlParserContext(null, nsmgr, null, XmlSpace.None);
foreach (XmlNode item in list)
{
//Create the reader.
XmlTextReader itemReader = new XmlTextReader(item.OuterXml, XmlNodeType.Element, context);
Issue issue = (Issue)s.Deserialize(itemReader);
issues.Add(issue);
}
return issues;
}
示例14: LoadPrimsFromXml
public static void LoadPrimsFromXml(Scene scene, string fileName, bool newIDS, Vector3 loadOffset)
{
XmlDocument doc = new XmlDocument();
XmlNode rootNode;
if (fileName.StartsWith("http:") || File.Exists(fileName))
{
XmlTextReader reader = new XmlTextReader(fileName);
reader.WhitespaceHandling = WhitespaceHandling.None;
doc.Load(reader);
reader.Close();
rootNode = doc.FirstChild;
foreach (XmlNode aPrimNode in rootNode.ChildNodes)
{
SceneObjectGroup obj = SceneObjectSerializer.FromOriginalXmlFormat(aPrimNode.OuterXml);
if (newIDS)
{
obj.ResetIDs();
}
//if we want this to be a import method then we need new uuids for the object to avoid any clashes
//obj.RegenerateFullIDs();
scene.AddNewSceneObject(obj, true);
}
}
else
{
throw new Exception("Could not open file " + fileName + " for reading");
}
}
示例15: XmlStorage
/// <summary>
/// Constructs an XmlStorage class
/// </summary>
/// <param name="fileName">Xml file to use</param>
public XmlStorage(string fileName)
{
this.isRoot = true;
this.root = this;
this.fileName = fileName;
this.name = "Root";
try
{
IO.FileStream stream = new IO.FileStream(fileName, IO.FileMode.Open, IO.FileAccess.Read);
Xml.XmlTextReader reader = new Xml.XmlTextReader(stream);
try
{
this.ReadElements(reader);
}
finally
{
reader.Close();
stream.Close();
}
}
catch (IO.FileNotFoundException)
{}
}