本文整理汇总了C#中System.Xml.XmlReaderSettings类的典型用法代码示例。如果您正苦于以下问题:C# XmlReaderSettings类的具体用法?C# XmlReaderSettings怎么用?C# XmlReaderSettings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XmlReaderSettings类属于System.Xml命名空间,在下文中一共展示了XmlReaderSettings类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FixNuSpec
private static void FixNuSpec(ProjectVersion version, string file)
{
XNamespace ns = "http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd";
var readerSettings = new XmlReaderSettings
{
IgnoreComments = false,
IgnoreWhitespace = false
};
XDocument doc;
using (var reader = XmlReader.Create(file, readerSettings))
{
doc = XDocument.Load(reader);
}
var versionElement = doc.Descendants(ns + "version").Single();
versionElement.Value = version.FullText;
var dependency = doc.Descendants(ns + "dependency").Where(x => (string)x.Attribute("id") == "NodaTime").FirstOrDefault();
if (dependency != null)
{
dependency.SetAttributeValue("version", version.Dependency);
}
var writerSettings = new XmlWriterSettings
{
Encoding = new UTF8Encoding(false),
Indent = false,
NewLineHandling = NewLineHandling.None,
};
using (var writer = XmlWriter.Create(file, writerSettings))
{
doc.Save(writer);
}
}
示例2: XmlResolver
public void XmlResolver ()
{
XmlReaderSettings xrs = new XmlReaderSettings ();
// setter-only property
xrs.XmlResolver = new ConcreteXmlResolver ();
xrs.XmlResolver = null;
}
示例3: GetPatents
//read XML file for patent info
public static SortedList<int, Patent> GetPatents()
{
XmlDocument doc = new XmlDocument();
//if file doesn't exist, create it
if (!File.Exists("Patents.xml"))
doc.Save("Patents.xml");
SortedList<int, Patent> patents = new SortedList<int, Patent>();
XmlReaderSettings readerSettings = new XmlReaderSettings();
readerSettings.IgnoreWhitespace = true;
readerSettings.IgnoreComments = true;
XmlReader readXml = null;
try
{
readXml = XmlReader.Create(path, readerSettings);
if (readXml.ReadToDescendant("Patent")) //read to first Patent node
{
do
{
Patent patent = new Patent();
patent.Number = Convert.ToInt32(readXml["Number"]);
readXml.ReadStartElement("Patent");
patent.AppNumber = readXml.ReadElementContentAsString();
patent.Description = readXml.ReadElementContentAsString();
patent.FilingDate = DateTime.Parse(readXml.ReadElementContentAsString());
patent.Inventor = readXml.ReadElementContentAsString();
patent.Inventor2 = readXml.ReadElementContentAsString();
int key = patent.Number; //assign key to value
patents.Add(key, patent); //add key-value pair to list
}
while (readXml.ReadToNextSibling("Patent"));
}
}
catch (XmlException ex)
{
MessageBox.Show(ex.Message, "Xml Error");
}
catch (IOException ex)
{
MessageBox.Show(ex.Message, "IO Exception");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Exception Occurred");
}
finally
{
if (readXml != null)
readXml.Close();
}
return patents;
}
示例4: CreateXmlReaderSettings
private static XmlReaderSettings CreateXmlReaderSettings(XmlSchema xmlSchema)
{
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas.Add(xmlSchema);
return settings;
}
示例5: Read
/// <summary>
/// Reads the PAP message from the specified stream.
/// </summary>
/// <param name="stream">The stream.</param>
/// <returns></returns>
public static PapMessage Read(Stream stream)
{
XmlReaderSettings settings =
new XmlReaderSettings
{
CheckCharacters = true,
CloseInput = true,
ConformanceLevel = System.Xml.ConformanceLevel.Document,
DtdProcessing = DtdProcessing.Parse,
IgnoreComments = true,
ValidationType = ValidationType.DTD
};
XmlReader reader = XmlReader.Create(stream, settings);
try
{
// Deserialize the data
XmlSerializer serializer = new XmlSerializer(typeof(PapRoot));
object resultRoot = serializer.Deserialize(reader);
// Extract the response object from the appropriate root
PapMessage response = null;
if (resultRoot is PapRoot)
{
response = ((PapRoot)resultRoot).Response;
}
return response;
}
finally
{
reader.Close();
}
}
示例6: StartupLoad
private void StartupLoad()
{
// Init class properties
SearchTypes = new List<string>();
// Load stuff
XmlReaderSettings settingsReaderSettings = new XmlReaderSettings();
settingsReaderSettings.ValidationType = ValidationType.Schema;
try
{
settingsReaderSettings.Schemas.Add("http://www.w3.org/2001/XMLSchema", "SettingsSchema.xsd");
}
catch (System.IO.IOException e)
{
ErrorDialogs.DetailedError("IO Exception", "Unable to read critical config file SettingsSchema.xsd.", e.Message);
throw;
}
// Settings
XmlReader settingsFileReader;
try
{
settingsFileReader = XmlReader.Create("Settings.xml", settingsReaderSettings);
}
catch (System.IO.IOException e)
{
ErrorDialogs.DetailedError("IO Exception", "Unable to read critical config file Settings.xml.", e.Message);
throw;
}
settingsFileReader.MoveToContent();
settingsFileReader.ReadToFollowing("SearchType");
SearchTypes.Add(settingsFileReader.GetAttribute("Name"));
settingsFileReader.Close();
}
示例7: ReadXml
private static byte[] ReadXml(Stream data)
{
data.Position = 0;
var settings = new XmlReaderSettings
{
CloseInput = false,
IgnoreComments = true,
IgnoreWhitespace = true,
IgnoreProcessingInstructions = true,
};
using (var reader = XmlReader.Create(data, settings))
{
try
{
if (!reader.ReadToFollowing("KeyFile"))
return null;
if (!reader.ReadToDescendant("Key"))
return null;
if (!reader.ReadToDescendant("Data"))
return null;
var base64 = reader.ReadElementContentAsString();
return Convert.FromBase64String(base64);
}
catch (XmlException)
{
return null;
}
}
}
示例8: LoadFromXml
private static IEnumerable<StorageAccountAdapter> LoadFromXml()
{
List<StorageAccountAdapter> accounts = new List<StorageAccountAdapter>();
XmlReaderSettings settings = new XmlReaderSettings();
settings.IgnoreComments = true;
using (XmlReader reader = XmlReader.Create("accounts.xml"))
{
XmlDocument doc = new XmlDocument();
doc.Load(reader);
var nodes = doc.DocumentElement.SelectNodes("/accounts/account").OfType<XmlNode>().ToList();
foreach (XmlNode node in nodes)
{
StorageAccountAdapter adapter = CreateAccount(node);
if (adapter != null)
{
accounts.Add(adapter);
}
}
}
return accounts.OrderBy(f => f.Name);
}
示例9: LoadRuleFile
private void LoadRuleFile()
{
if (string.IsNullOrEmpty(_fileName))
{
throw new NullReferenceException("Please set file name first");
}
if (!File.Exists(_fileName))
{
throw new Exception(string.Format("File {0} does not exists on disk",Path.GetFullPath(_fileName)));
}
using (Stream stream = File.OpenRead(_fileName))
{
var settings = new XmlReaderSettings
{
ValidationType = ValidationType.Schema,
};
using (XmlReader reader = XmlReader.Create(stream, settings))
{
XDocument fileDocument = XDocument.Load(reader, LoadOptions.PreserveWhitespace);
LoadRulesData(fileDocument);
reader.Close();
}
stream.Close();
}
}
示例10: ReadAsXmlReader
public static XmlReader ReadAsXmlReader(this HttpContent content, XmlReaderSettings settings)
{
FX.ThrowIfNull(content, "content");
FX.ThrowIfNull(content, "settings");
return XmlReader.Create(content.ContentReadStream, settings);
}
示例11: Validate
public bool Validate()
{
is_success_ = false;
XmlDocument document = new XmlDocument();
document.Load(xml_filename_);
XmlReaderSettings setting = new XmlReaderSettings();
setting.CloseInput = true;
setting.ValidationEventHandler += Handler;
setting.ValidationType = ValidationType.Schema;
setting.Schemas.Add(null, xsd_filename_);
setting.ValidationFlags = XmlSchemaValidationFlags.ReportValidationWarnings |
XmlSchemaValidationFlags.ProcessIdentityConstraints |
XmlSchemaValidationFlags.ProcessInlineSchema |
XmlSchemaValidationFlags.ProcessSchemaLocation;
is_success_ = true;
using (XmlReader validationReader = XmlReader.Create(xml_filename_, setting))
{
while (validationReader.Read())
{
/* do nothing for while */
}
}
return is_success_;
}
示例12: CreateXmlReader
private XmlReader CreateXmlReader()
{
XmlReaderSettings settings = new XmlReaderSettings();
settings.ConformanceLevel = ConformanceLevel.Fragment;
return XmlTextReader.Create(_fs, settings);
}
示例13: LoadTextSource
/// <summary>
/// Loads the WorldMarket data from text source.
/// </summary>
/// <param name="xmlText">The UTF-8 text source.</param>
public static WorldMarket LoadTextSource(string xmlText)
{
try
{
XmlReaderSettings readerSettings = new XmlReaderSettings();
#if !(NETFX_CORE || SILVERLIGHT)
XmlSchema sch = XmlSchema.Read(new System.IO.StringReader(Properties.Resources.market_schema), null);
readerSettings.Schemas.Add(sch);
readerSettings.ValidationType = ValidationType.Schema;
#endif
XmlReader market = XmlReader.Create(new System.IO.StringReader(xmlText), readerSettings);
XmlSerializer ser = new XmlSerializer(typeof(System.Resources.WorldMarket));
System.Resources.WorldMarket wm = (System.Resources.WorldMarket)ser.Deserialize(market);
WorldMarket result = new WorldMarket();
foreach (var s in wm.Sectors) { result.mSectors.Add(new Sector(s)); }
foreach (var s in wm.Industries) { result.mIndustries.Add(new Industry(s, result)); }
foreach (var s in wm.Currencies) { result.mCurrencies.Add(new CurrencyInfo(s)); }
foreach (var s in wm.Countries) { result.mCountries.Add(new CountryInfo(s, result)); }
foreach (var s in wm.StockExchanges) { result.mStockExchanges.Add(new StockExchange(s, result)); }
foreach (var s in wm.Indices) { result.mIndices.Add(new YID(s, result)); }
foreach (var s in wm.FundCategories) { result.mFundCategories.Add(new FundCategory(s)); }
foreach (var s in wm.FundFamilies) { result.mFundFamilies.Add(new FundFamily(s)); }
return result;
}
catch (Exception ex)
{
throw new Exception("The XML text is not valid. See InnerException for more details.", ex);
}
}
示例14: PairNodes
public void PairNodes(Node node1, Node node2)
{
try
{
XmlReaderSettings xmlReaderSettings = new XmlReaderSettings();
xmlReaderSettings.IgnoreWhitespace = true;
xmlReaderSettings.IgnoreComments = true;
//if (!File.Exists(XmlFilePath)) return;
var document = new XmlDocument();
document.Load(XmlFilePath);
var xmlElementList = document.GetElementsByTagName("NodePairs");
var newXmlElement = document.CreateElement("NodePair");
var firstNode = document.CreateElement("Node");
var secondNode = document.CreateElement("Node");
firstNode.SetAttribute("Id", node1.Id);
secondNode.SetAttribute("Id", node2.Id);
newXmlElement.AppendChild(firstNode);
newXmlElement.AppendChild(secondNode);
xmlElementList[0].AppendChild(newXmlElement);
document.Save(XmlFilePath);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
示例15: LoadScript
private static Script LoadScript(string fileName)
{
try
{
var settings = new XmlReaderSettings();
string resourceName = typeof(ScriptLoader).Namespace + ".Script-v1.xsd";
using (var stream = typeof(ScriptLoader).Assembly.GetManifestResourceStream(resourceName))
using (var reader = XmlReader.Create(stream))
{
settings.Schemas.Add(Constants.ScriptNs, reader);
}
settings.ValidationType = ValidationType.Schema;
using (var reader = XmlReader.Create(fileName, settings))
{
var serializer = new XmlSerializer(typeof(Script));
return (Script)serializer.Deserialize(reader);
}
}
catch (Exception ex)
{
throw new ScriptException(UILabels.InvalidScript, ex);
}
}