本文整理汇总了C#中System.Xml.XmlNodeReader.MoveToElement方法的典型用法代码示例。如果您正苦于以下问题:C# XmlNodeReader.MoveToElement方法的具体用法?C# XmlNodeReader.MoveToElement怎么用?C# XmlNodeReader.MoveToElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlNodeReader
的用法示例。
在下文中一共展示了XmlNodeReader.MoveToElement方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: process_element
private abstract_Element process_element( XmlNodeReader nodeReader, int current_page_count )
{
string type = String.Empty;
string subtype = String.Empty;
// Step through all the attributes until the type is found
nodeReader.MoveToFirstAttribute();
do
{
// Get the type attribute
if ( nodeReader.Name.ToUpper().Trim() == "TYPE" )
{
type = nodeReader.Value;
}
// Get the subtype attribute
if ( nodeReader.Name.ToUpper().Trim() == "SUBTYPE" )
{
subtype = nodeReader.Value;
}
} while (nodeReader.MoveToNextAttribute() );
// Make sure a type was specified
if ( type == String.Empty )
return null;
// Build the element
abstract_Element newElement = Element_Factory.getElement( type, subtype );
// If thie element was null, return null
if (newElement == null)
return null;
// Set the page number for post back reasons
newElement.Template_Page = current_page_count;
// Some special logic here
if ((newElement.Type == Element_Type.Type) && ( newElement.Display_SubType == "form" ))
{
(( Type_Format_Form_Element )newElement).Set_Postback("javascript:__doPostBack('newpagebutton" + current_page_count + "','')");
}
if ((newElement.Type == Element_Type.Title) && (newElement.Display_SubType == "form"))
{
complexMainTitleExists = true;
}
if ((newElement.Type == Element_Type.Note) && (newElement.Display_SubType == "complex"))
{
((Note_Complex_Element)newElement).Include_Statement_Responsibility = !complexMainTitleExists;
}
// Now, step through all the attributes again
nodeReader.MoveToFirstAttribute();
do
{
switch( nodeReader.Name.ToUpper().Trim() )
{
case "REPEATABLE":
bool repeatable;
if ( Boolean.TryParse( nodeReader.Value, out repeatable ))
newElement.Repeatable = repeatable;
break;
case "MANDATORY":
bool mandatory;
if (Boolean.TryParse(nodeReader.Value, out mandatory))
newElement.Mandatory = mandatory;
break;
case "READONLY":
bool isReadOnly;
if (Boolean.TryParse(nodeReader.Value, out isReadOnly))
newElement.Read_Only = isReadOnly;
break;
case "ACRONYM":
newElement.Acronym = nodeReader.Value;
break;
}
} while (nodeReader.MoveToNextAttribute() );
// Move back to the element, if there were attributes (should be)
nodeReader.MoveToElement();
// Is there element_data?
if ( !nodeReader.IsEmptyElement )
{
nodeReader.Read();
if (( nodeReader.NodeType == XmlNodeType.Element ) && ( nodeReader.Name.ToLower() == "element_data" ))
{
// Create the new tree
StringWriter sw = new StringWriter();
XmlTextWriter tw = new XmlTextWriter( sw );
tw.WriteNode( nodeReader, true );
tw.Close();
// Let the element process this inner data
newElement.Read_XML( new XmlTextReader( new StringReader( sw.ToString() )));
}
}
//.........这里部分代码省略.........
示例2: RemoveNamespaces
/// <summary>
/// This removes namespaces from an XML Element (Scott)
/// </summary>
/// <param name="xeElement"></param>
/// <returns></returns>
protected string RemoveNamespaces(XmlNode xeElement)
{
StringWriter swOutput = new System.IO.StringWriter();
XmlTextWriter xtwWriter = new XmlTextWriter(swOutput);
//xtwWriter.WriteStartDocument();
XmlNodeReader xnrReader = new XmlNodeReader(xeElement);
while (xnrReader.Read())
{
switch (xnrReader.NodeType)
{
case XmlNodeType.Element:
xtwWriter.WriteStartElement(xnrReader.Name);
if (xnrReader.HasAttributes)
{
while (xnrReader.MoveToNextAttribute())
{
if (xnrReader.Name != "xmlns")
{
xtwWriter.WriteAttributeString(xnrReader.Name, xnrReader.Value);
}
}
xnrReader.MoveToElement();
}
if (xnrReader.IsEmptyElement)
{
xtwWriter.WriteEndElement();
}
break;
case XmlNodeType.Text:
xtwWriter.WriteString(xnrReader.Value);
break;
case XmlNodeType.CDATA:
xtwWriter.WriteCData(xnrReader.Value);
break;
case XmlNodeType.ProcessingInstruction:
xtwWriter.WriteProcessingInstruction(xnrReader.Name, xnrReader.Value);
break;
case XmlNodeType.Comment:
xtwWriter.WriteComment(xnrReader.Value);
break;
case XmlNodeType.EntityReference:
xtwWriter.WriteEntityRef(xnrReader.Name);
break;
case XmlNodeType.EndElement:
xtwWriter.WriteEndElement();
break;
}
}
//xtwWriter.WriteEndDocument();
xtwWriter.Flush();
xtwWriter.Close();
xnrReader.Close();
string sOutput = swOutput.ToString();
return sOutput;
}
示例3: ParseAndSendMessages
/// <summary>
/// Parses an IM log file and sends the information to GDS
/// </summary>
/// <param name="logFile">The IM conversations log file</param>
/// <param name="lastIndexed">messages older than this will not be sent to GDS</param>
private void ParseAndSendMessages(string logFile, DateTime lastIndexed)
{
XmlDocument doc = new XmlDocument();
doc.Load(logFile);
XmlNodeReader reader = new XmlNodeReader(doc);
// reset user and buddy name
userName = null;
buddyName = null;
// Moves the reader to the root element.
reader.MoveToContent();
// move to the first message
reader.Read();
while(reader.LocalName == "Message")
{
// check the date of the message - if older skip
reader.MoveToAttribute("DateTime");
DateTime messageDateTime = DateTime.Parse(reader.Value);
reader.MoveToElement();
// if older than the last indexing time, skip the message
if (messageDateTime.CompareTo(lastIndexed) <= 0)
{
reader.Skip();
continue;
}
// get message data
MSNMessageData messageData = ParseMessageData(reader.ReadOuterXml());
// send this message to GDS for indexing
SendMessageData(messageData);
}
}