本文整理匯總了C#中System.Xml.XmlTextReader.Skip方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlTextReader.Skip方法的具體用法?C# XmlTextReader.Skip怎麽用?C# XmlTextReader.Skip使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.XmlTextReader
的用法示例。
在下文中一共展示了XmlTextReader.Skip方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Read
public static DatabaseConfiguration Read(string file)
{
DatabaseConfiguration config = new DatabaseConfiguration ();
StreamReader s = new StreamReader (file);
using (s) {
XmlTextReader tr = new XmlTextReader (s);
tr.MoveToContent ();
if (tr.IsEmptyElement)
return config;
tr.ReadStartElement ("Configuration");
tr.MoveToContent ();
while (tr.NodeType != XmlNodeType.EndElement) {
if (tr.NodeType != XmlNodeType.Element || tr.IsEmptyElement) {
tr.Skip ();
}
else if (tr.LocalName == "DisabledAddins") {
// For back compatibility
tr.ReadStartElement ();
tr.MoveToContent ();
while (tr.NodeType != XmlNodeType.EndElement) {
if (tr.NodeType == XmlNodeType.Element && tr.LocalName == "Addin")
config.addinStatus [tr.ReadElementString ()] = null;
else
tr.Skip ();
tr.MoveToContent ();
}
tr.ReadEndElement ();
}
else if (tr.LocalName == "AddinStatus") {
tr.ReadStartElement ();
tr.MoveToContent ();
while (tr.NodeType != XmlNodeType.EndElement) {
if (tr.NodeType == XmlNodeType.Element && tr.LocalName == "Addin") {
string aid = tr.GetAttribute ("id");
string senabled = tr.GetAttribute ("enabled");
if (senabled.Length == 0 || senabled == "True")
config.addinStatus [aid] = config;
else
config.addinStatus [aid] = null;
}
tr.Skip ();
tr.MoveToContent ();
}
tr.ReadEndElement ();
}
tr.MoveToContent ();
}
}
return config;
}
示例2: Read
public static DatabaseConfiguration Read (string file)
{
DatabaseConfiguration config = new DatabaseConfiguration ();
StreamReader s = new StreamReader (file);
using (s) {
XmlTextReader tr = new XmlTextReader (s);
tr.MoveToContent ();
tr.ReadStartElement ("Configuration");
tr.MoveToContent ();
tr.ReadStartElement ("DisabledAddins");
tr.MoveToContent ();
if (!tr.IsEmptyElement) {
while (tr.NodeType != XmlNodeType.EndElement) {
if (tr.NodeType == XmlNodeType.Element) {
if (tr.LocalName == "Addin")
config.DisabledAddins.Add (tr.ReadElementString ());
}
else
tr.Skip ();
tr.MoveToContent ();
}
}
}
return config;
}
示例3: LoadXML
/// <summary> Loads any XML case file with it's Elements, Attributes and Values. </summary>
/// <param name="fileURL"> Which file to load. </param>
/// <returns> Load succeeded? </returns>
bool LoadXML(string fileURL)
{
reader = new XmlTextReader(fileURL);
if (reader.Read() && reader.NodeType == XmlNodeType.XmlDeclaration)
{
reader.Skip();
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
Program.form1.labelTest.Text += "+"+reader.Name;
Program.form1.labelTest.Text += reader.AttributeCount;
//Program.form1.labelTest.Text += "-"+reader.Value;
for (int i = 0; i < reader.AttributeCount; i++)
Program.form1.labelTest.Text += "#" + reader.GetAttribute(i);
break;
case XmlNodeType.Text:
//Program.form1.labelTest.Text += " TEXT " + reader.Name;
Program.form1.labelTest.Text += " TEXT " + reader.Value;
break;
case XmlNodeType.EndElement:
Program.form1.labelTest.Text += ">" + reader.Name;
//Program.form1.labelTest.Text += ">" + reader.Value;
break;
default:
if (reader.NodeType != XmlNodeType.Whitespace)
Program.form1.labelTest.Text += " F A L S E ! ! ! ! ! ";
break;
}
}
}
return true;
}
示例4: CAGCategory
public CAGCategory( CAGCategory parent, XmlTextReader xml )
{
m_Parent = parent;
if ( xml.MoveToAttribute( "title" ) )
m_Title = xml.Value;
else
m_Title = "empty";
if ( m_Title == "Docked" )
m_Title = "Docked 2";
if ( xml.IsEmptyElement )
{
m_Nodes = new CAGNode[0];
}
else
{
ArrayList nodes = new ArrayList();
while ( xml.Read() && xml.NodeType != XmlNodeType.EndElement )
{
if ( xml.NodeType == XmlNodeType.Element && xml.Name == "object" )
nodes.Add( new CAGObject( this, xml ) );
else if ( xml.NodeType == XmlNodeType.Element && xml.Name == "category" )
nodes.Add( new CAGCategory( this, xml ) );
else
xml.Skip();
}
m_Nodes = (CAGNode[])nodes.ToArray( typeof( CAGNode ) );
}
}
示例5: readXML
public DataTable readXML(string qID, string xmlPath)
{
DataTable dt = new DataTable();
string quest = "";
string part = "";
dt.Columns.Add("name");
dt.Columns.Add("id");
try
{
XmlTextReader reader = new XmlTextReader(xmlPath);
while (reader.Read())
{
switch (reader.Name)
{
case "question":
if (reader.AttributeCount > 0 && qID.ToUpper() == reader.GetAttribute("value").ToUpper())//OM DETR FINN
{
part = reader.GetAttribute("part").ToUpper();
}
else
{
reader.Skip();
}
break;
case "txt":
quest = reader.ReadString(); //Frågan sparas till en string behöver ha en tupple
break;
case "qone":
dt.Rows.Add();//Nedan är svarsalternativen
dt.Rows[dt.Rows.Count - 1]["id"] = reader.GetAttribute("id").ToUpper();
dt.Rows[dt.Rows.Count - 1]["name"] = reader.ReadString();
break;
case "qtwo":
dt.Rows.Add();
dt.Rows[dt.Rows.Count - 1]["id"] = reader.GetAttribute("id").ToUpper();
dt.Rows[dt.Rows.Count - 1]["name"] = reader.ReadString();
break;
case "qthree":
dt.Rows.Add();
dt.Rows[dt.Rows.Count - 1]["id"] = reader.GetAttribute("id").ToUpper();
dt.Rows[dt.Rows.Count - 1]["name"] = reader.ReadString();
break;
case "qfour":
dt.Rows.Add();
dt.Rows[dt.Rows.Count - 1]["id"] = reader.GetAttribute("id").ToUpper();
dt.Rows[dt.Rows.Count - 1]["name"] = reader.ReadString();
break;
}
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
return null;
}
return dt;
}
示例6: XmlDocumentationToText
public static string XmlDocumentationToText(string xmlDoc)
{
System.Diagnostics.Debug.WriteLine(xmlDoc);
StringBuilder b = new StringBuilder();
try {
using (XmlTextReader reader = new XmlTextReader(new StringReader("<root>" + xmlDoc + "</root>"))) {
reader.XmlResolver = null;
while (reader.Read()) {
switch (reader.NodeType) {
case XmlNodeType.Text:
b.Append(reader.Value);
break;
case XmlNodeType.Element:
switch (reader.Name) {
case "filterpriority":
reader.Skip();
break;
case "returns":
b.AppendLine();
b.Append("Returns: ");
break;
case "param":
b.AppendLine();
b.Append(reader.GetAttribute("name") + ": ");
break;
case "remarks":
b.AppendLine();
b.Append("Remarks: ");
break;
case "see":
if (reader.IsEmptyElement) {
b.Append(reader.GetAttribute("cref"));
} else {
reader.MoveToContent();
if (reader.HasValue) {
b.Append(reader.Value);
} else {
b.Append(reader.GetAttribute("cref"));
}
}
break;
}
break;
}
}
}
return b.ToString();
} catch (XmlException) {
return xmlDoc;
}
}
示例7: XmlAddCAGCategory
public XmlAddCAGCategory( XmlAddCAGCategory parent, XmlTextReader xml )
{
m_Parent = parent;
if ( xml.MoveToAttribute( "title" ) )
{
if(xml.Value == "Add Menu")
m_Title = "XmlAdd Menu";
else
m_Title = xml.Value;
}
else
m_Title = "empty";
if ( m_Title == "Docked" )
m_Title = "Docked 2";
if ( xml.IsEmptyElement )
{
m_Nodes = new XmlAddCAGNode[0];
}
else
{
ArrayList nodes = new ArrayList();
try{
while ( xml.Read() && xml.NodeType != XmlNodeType.EndElement )
{
if ( xml.NodeType == XmlNodeType.Element && xml.Name == "object" )
nodes.Add( new XmlAddCAGObject( this, xml ) );
else if ( xml.NodeType == XmlNodeType.Element && xml.Name == "category" )
nodes.Add( new XmlAddCAGCategory( this, xml ) );
else
xml.Skip();
}
} catch (Exception ex){
Console.WriteLine("XmlCategorizedAddGump: Corrupted Data/objects.xml file detected. Not all XmlCAG objects loaded. {0}", ex);
}
m_Nodes = (XmlAddCAGNode[])nodes.ToArray( typeof( XmlAddCAGNode ) );
}
}
示例8: ReadGen
public override void ReadGen(APGen gen, string streamName, XmlTextReader reader)
{
StreamName = streamName;
GenHost = gen.GenHost;
while (reader.MoveToNextAttribute())
{
switch (reader.Name)
{
case "type": TypeName = reader.Value; break;
case "name": Name = reader.Value; break;
default: ThrowException(APResource.GetString(APResource.APGen_UnrecognizedAttribute, reader.Name), reader); break;
}
}
if (Name == null || TypeName == null)
ThrowException(APResource.GetString(APResource.APGen_MissingRequiredAttribute, "section", "name or type"), reader);
reader.MoveToElement();
reader.Skip();
}
示例9: read
public DataTable read(string testID)
{
DataTable dt = new DataTable();
dt.Columns.Add("name"); //Fråga 1, Fråga 2---
dt.Columns.Add("id"); //Fråge id:et
dt.Columns.Add("order");
try
{
XmlTextReader reader = new XmlTextReader(new StringReader(getXml(testID)));
while (reader.Read())
{
switch (reader.Name)
{
case "question":
dt.Rows.Add();
dt.Rows[dt.Rows.Count - 1]["order"] = reader.GetAttribute("order").ToUpper();
dt.Rows[dt.Rows.Count - 1]["id"] = reader.GetAttribute("value").ToUpper();
// Random random = new Random();
reader.Skip();
break;
}
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
}
dt.DefaultView.Sort = "order";
dt = dt.DefaultView.ToTable();
for (int i = 0; i < dt.Rows.Count; i++)
{
dt.Rows[i]["name"] = (i + 1).ToString();
}
return dt;
}
示例10: ReadGenericProjectType
static string ReadGenericProjectType (string file)
{
using (XmlTextReader tr = new XmlTextReader (file)) {
tr.MoveToContent ();
if (tr.LocalName != "Project")
return null;
if (tr.IsEmptyElement)
return null;
tr.ReadStartElement ();
tr.MoveToContent ();
if (tr.LocalName != "PropertyGroup")
return null;
if (tr.IsEmptyElement)
return null;
tr.ReadStartElement ();
tr.MoveToContent ();
while (tr.NodeType != XmlNodeType.EndElement) {
if (tr.NodeType == XmlNodeType.Element && !tr.IsEmptyElement && tr.LocalName == "ItemType")
return tr.ReadElementString ();
tr.Skip ();
}
return null;
}
}
示例11: ParseSettingString
private void ParseSettingString (string source)
{
XmlTextReader xtr = new XmlTextReader (source,
XmlNodeType.Element, null);
xtr.Read ();
if (xtr.Name != "DataViewSettingCollectionString")
// easy way to throw the expected exception ;-)
xtr.ReadStartElement ("DataViewSettingCollectionString");
if (xtr.IsEmptyElement)
return; // MS does not change the value.
xtr.Read ();
do {
xtr.MoveToContent ();
if (xtr.NodeType == XmlNodeType.EndElement)
break;
if (xtr.NodeType == XmlNodeType.Element)
ReadTableSetting (xtr);
else
xtr.Skip ();
} while (!xtr.EOF);
if (xtr.NodeType == XmlNodeType.EndElement)
xtr.ReadEndElement ();
}
示例12: ReadConfigFile
private void ReadConfigFile (XmlTextReader reader)
{
//int depth = reader.Depth;
for (reader.MoveToContent ();
!reader.EOF && reader.NodeType != XmlNodeType.EndElement;
reader.MoveToContent ()) {
string name = reader.Name;
if (name == "configSections") {
if (reader.HasAttributes)
ThrowException ("Unrecognized attribute in <configSections>.", reader);
if (reader.IsEmptyElement)
reader.Skip ();
else {
reader.Read ();
reader.MoveToContent ();
if (reader.NodeType != XmlNodeType.EndElement)
ReadSections (reader, null);
reader.ReadEndElement ();
}
} else if (name != null && name != "") {
StorePending (name, reader);
MoveToNextElement (reader);
} else {
MoveToNextElement (reader);
}
}
}
示例13: ReadSection
private void ReadSection (XmlTextReader reader, string sectionName)
{
string attName;
string nameValue = null;
string typeValue = null;
string allowLoc = null, allowDef = null;
bool requirePermission = false;
string requirePer = null;
bool allowLocation = true;
AllowDefinition allowDefinition = AllowDefinition.Everywhere;
while (reader.MoveToNextAttribute ()) {
attName = reader.Name;
if (attName == null)
continue;
if (attName == "allowLocation") {
if (allowLoc != null)
ThrowException ("Duplicated allowLocation attribute.", reader);
allowLoc = reader.Value;
allowLocation = (allowLoc == "true");
if (!allowLocation && allowLoc != "false")
ThrowException ("Invalid attribute value", reader);
continue;
}
if (attName == "requirePermission") {
if (requirePer != null)
ThrowException ("Duplicated requirePermission attribute.", reader);
requirePer = reader.Value;
requirePermission = (requirePer == "true");
if (!requirePermission && requirePer != "false")
ThrowException ("Invalid attribute value", reader);
continue;
}
if (attName == "allowDefinition") {
if (allowDef != null)
ThrowException ("Duplicated allowDefinition attribute.", reader);
allowDef = reader.Value;
try {
allowDefinition = (AllowDefinition) Enum.Parse (
typeof (AllowDefinition), allowDef);
} catch {
ThrowException ("Invalid attribute value", reader);
}
continue;
}
if (attName == "type") {
if (typeValue != null)
ThrowException ("Duplicated type attribute.", reader);
typeValue = reader.Value;
continue;
}
if (attName == "name") {
if (nameValue != null)
ThrowException ("Duplicated name attribute.", reader);
nameValue = reader.Value;
if (nameValue == "location")
ThrowException ("location is a reserved section name", reader);
continue;
}
ThrowException ("Unrecognized attribute.", reader);
}
if (nameValue == null || typeValue == null)
ThrowException ("Required attribute missing", reader);
if (sectionName != null)
nameValue = sectionName + '/' + nameValue;
reader.MoveToElement();
object o = LookForFactory (nameValue);
if (o != null && o != removedMark)
ThrowException ("Already have a factory for " + nameValue, reader);
SectionData section = new SectionData (nameValue, typeValue, allowLocation,
allowDefinition, requirePermission);
section.FileName = fileName;
factories [nameValue] = section;
if (reader.IsEmptyElement)
reader.Skip ();
else {
reader.Read ();
reader.MoveToContent ();
if (reader.NodeType != XmlNodeType.EndElement)
// sub-section inside a section
ReadSections (reader, nameValue);
reader.ReadEndElement ();
}
reader.MoveToContent ();
}
示例14: GetDocumentation
/// <summary>
/// Converts the xml documentation string into a plain text string.
/// </summary>
private static string GetDocumentation(string ExtendedData)
{
System.IO.StringReader reader = new System.IO.StringReader("<docroot>" + ExtendedData + "</docroot>");
XmlTextReader xml = new XmlTextReader(reader);
StringBuilder ret = new StringBuilder();
////Regex whitespace = new Regex(@"\s+");
bool blnExceptionStarted = false;
try
{
xml.Read();
do
{
if (xml.NodeType == XmlNodeType.Element)
{
string elname = xml.Name.ToLowerInvariant();
switch (elname)
{
case "filterpriority":
xml.Skip();
break;
case "remarks":
ret.Append(Environment.NewLine);
ret.Append("Remarks:");
ret.Append(Environment.NewLine);
break;
case "example":
ret.Append(Environment.NewLine);
ret.Append("Example:");
ret.Append(Environment.NewLine);
break;
case "exception":
ret.Append(Environment.NewLine);
if (blnExceptionStarted == false)
{
ret.Append("Exception:");
ret.Append(Environment.NewLine);
blnExceptionStarted = true;
}
ret.Append(GetCref(xml["cref"]));
ret.Append(": ");
xml.Skip();
break;
case "returns":
xml.Skip();
//ret.Append(Environment.NewLine);
//ret.Append("Returns: ");
break;
case "see":
ret.Append(GetCref(xml["cref"]));
ret.Append(xml["langword"]);
break;
case "seealso":
ret.Append(Environment.NewLine);
ret.Append("See also: ");
ret.Append(GetCref(xml["cref"]));
break;
case "paramref":
ret.Append(xml["name"]);
break;
case "param":
ret.Append(Environment.NewLine);
ret.Append(whitespace.Replace(xml["name"].Trim(), " "));
ret.Append(": ");
break;
case "value":
ret.Append(Environment.NewLine);
ret.Append("Value: ");
ret.Append(Environment.NewLine);
break;
case "br":
case "para":
ret.Append(Environment.NewLine);
break;
}
}
else if (xml.NodeType == XmlNodeType.Text)
{
ret.Append(whitespace.Replace(xml.Value, " "));
}
} while (xml.Read());
}
catch (Exception e)
{
e.ToString();
return ExtendedData;
}
return ret.ToString();
}
示例15: GetLineNumber
/// <summary>
/// GetLineNumber is used when reporting errors in Animation XML
/// descriptions. It will find the line number of the first top level
/// node whose tag matches the provided value.
/// </summary>
/// <param name="source">Animation XML description</param>
/// <param name="tag">Tag of the node to find</param>
/// <returns>Line number of the tag, or the first line if nothing found</returns>
private static int GetLineNumber(string source, string tag)
{
// We'll manually walk through the source using an XmlTextReader
// so we can get the line number
using (XmlTextReader reader = new XmlTextReader(new StringReader(source)))
{
// Move to the document element
if (reader.Read())
{
// Loop though all the top level children
while (reader.Read())
{
// If this node matches, return its line number
if (string.Compare(reader.Name, tag, StringComparison.OrdinalIgnoreCase) == 0)
return reader.LineNumber;
// If this node has children, ignore them all
if (reader.NodeType == XmlNodeType.Element && !reader.IsEmptyElement)
reader.Skip();
}
}
}
// If we can't find it, just use the first line
return 1;
}