本文整理汇总了C#中System.Xml.XmlReader.MoveToElement方法的典型用法代码示例。如果您正苦于以下问题:C# XmlReader.MoveToElement方法的具体用法?C# XmlReader.MoveToElement怎么用?C# XmlReader.MoveToElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlReader
的用法示例。
在下文中一共展示了XmlReader.MoveToElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseColorAttributes
public static ColorEx ParseColorAttributes(XmlReader r)
{
float R = 0;
float G = 0;
float B = 0;
for (int i = 0; i < r.AttributeCount; i++)
{
r.MoveToAttribute(i);
// set the field in this object based on the element we just read
switch (r.Name)
{
case "R":
R = float.Parse(r.Value);
break;
case "G":
G = float.Parse(r.Value);
break;
case "B":
B = float.Parse(r.Value);
break;
}
}
r.MoveToElement(); //Moves the reader back to the element node.
r.MoveToElement(); //Moves the reader back to the element node.
if (R > 1 || G > 1 || B > 1)
{
R = R / 255;
G = G / 255;
B = B / 255;
}
return new ColorEx(R, G, B);
}
示例2: ReadContent
public static string ReadContent(XmlReader xr)
{
string rlt;
if (xr.NodeType != XmlNodeType.Element)
{
xr.MoveToElement();
}
rlt = xr.ReadString();
xr.MoveToElement();
return rlt;
}
示例3: ParseQuaternion
public static Quaternion ParseQuaternion(XmlReader r)
{
float w = 0;
float x = 0;
float y = 0;
float z = 0;
for (int i = 0; i < r.AttributeCount; i++)
{
r.MoveToAttribute(i);
// set the field in this object based on the element we just read
switch (r.Name)
{
case "w":
w = float.Parse(r.Value);
break;
case "x":
x = float.Parse(r.Value);
break;
case "y":
y = float.Parse(r.Value);
break;
case "z":
z = float.Parse(r.Value);
break;
}
}
r.MoveToElement(); //Moves the reader back to the element node.
return new Quaternion(w, x, y, z);
}
示例4: ReadXml
public static KeyValuePair<string, Property> ReadXml(XmlReader reader)
{
var key = reader.GetAttribute("Key");
var type = reader.GetAttribute("Type");
reader.MoveToElement();
reader.ReadStartElement("PropertyEntry");
Property value = null;
try
{
var t = Type.GetType(type);
value = (Property)GetSerializer(t).Deserialize(reader);
}
catch (Exception ex)
{
Console.WriteLine("Deserialization failed: " + ex.Message);
Console.WriteLine("Property Key: " + key);
Console.WriteLine("Property Type Qualified Name: " + type);
Console.WriteLine("Stacktrace: " + ex.StackTrace);
}
reader.ReadEndElement();
reader.MoveToContent();
if (value == null)
throw new Exception();
return new KeyValuePair<string, Property>(key, value);
}
示例5: ReadObject
public override object ReadObject(XmlReader reader)
{
OneWayAttachmentRequest OneWayAttachmentRequestField = null;
if (IsParentStartElement(reader, false, true))
{
OneWayAttachmentRequestField = new OneWayAttachmentRequest();
OneWayAttachmentRequestField.AnyAttr = ReadAnyAttribute(reader);
reader.Read();
if (IsChildStartElement(reader, "Param", true, true))
{
reader.Read();
if (IsAttribute(reader, "href"))
{
string contentID;
contentID = reader.Value;
reader.MoveToElement();
reader.ReadStartElement("Include", "http://www.w3.org/2004/08/xop/include");
reader.ReadEndElement();
OneWayAttachmentRequestField.Param = GetBodyPartContent(contentID, BodyParts);
}
else
{
OneWayAttachmentRequestField.Param = Convert.FromBase64String(reader.ReadString());
reader.ReadEndElement();
}
}
OneWayAttachmentRequestField.Any = ReadAnyElement(reader, false);
reader.ReadEndElement();
}
return OneWayAttachmentRequestField;
}
示例6: CreateResponseException
public static Exception CreateResponseException(XmlReader reader)
{
if (reader == null)
throw new ArgumentNullException("reader");
reader.MoveToElement();
if (!reader.ReadToDescendant("err"))
throw new XmlException("No error element found in XML");
int code = 0;
string message = (string) null;
while (reader.MoveToNextAttribute())
{
if (reader.LocalName == "code")
{
try
{
code = int.Parse(reader.Value, NumberStyles.Any, (IFormatProvider) NumberFormatInfo.InvariantInfo);
}
catch (FormatException ex)
{
throw new FlickrException("Invalid value found in code attribute. Value '" + (object) code + "' is not an integer");
}
}
else if (reader.LocalName == "msg")
message = reader.Value;
}
return (Exception) ExceptionHandler.CreateException(code, message);
}
示例7: AttributeAssignmentElementReadWrite
/// <summary>
/// Creates an instance of the ReadWriteAttributeAssignment using the provided XmlReader.
/// </summary>
/// <param name="reader">The XmlReader positioned at the AttributeAssignament node.</param>
/// <param name="schemaVersion">The version of the schema that was used to validate.</param>
public AttributeAssignmentElementReadWrite(XmlReader reader, XacmlVersion schemaVersion)
: base(XacmlSchema.Policy, schemaVersion)
{
if (reader == null) throw new ArgumentNullException("reader");
if (reader.LocalName == Consts.Schema1.ObligationElement.AttributeAssignment &&
ValidateSchema(reader, schemaVersion))
{
if (reader.HasAttributes)
{
// Load all the attributes
while (reader.MoveToNextAttribute())
{
if (reader.LocalName == Consts.Schema1.AttributeValueElement.DataType)
{
_dataType = reader.GetAttribute(Consts.Schema1.AttributeValueElement.DataType);
}
else if (reader.LocalName == Consts.Schema1.AttributeAssignmentElement.AttributeId)
{
_attributeId = reader.GetAttribute(Consts.Schema1.AttributeAssignmentElement.AttributeId);
}
}
reader.MoveToElement();
}
// Load the node contents
_contents = reader.ReadInnerXml();
}
else
{
throw new Exception(string.Format(Properties.Resource.exc_invalid_node_name, reader.LocalName));
}
}
示例8: HeightfieldTerrainGenerator
public HeightfieldTerrainGenerator(XmlReader r)
{
for (int i = 0; i < r.AttributeCount; i++)
{
r.MoveToAttribute(i);
switch (r.Name)
{
case "Type":
string type = r.Value;
Debug.Assert(type == "HeightfieldMosaic");
break;
case "MosaicName":
heightfieldName = r.Value;
break;
case "PreloadRadius":
preloadRadius = int.Parse(r.Value);
break;
case "OutsideHeight":
outsideHeight = float.Parse(r.Value);
break;
}
}
r.MoveToElement();
if (!r.IsEmptyElement)
{
do
{
r.Read();
} while (r.NodeType != XmlNodeType.EndElement);
}
Mosaic = new HeightfieldMosaic(heightfieldName, preloadRadius, outsideHeight);
Mosaic.MosaicModificationStateChanged += Mosaic_OnMosaicModificationStateChanged;
Mosaic.MosaicChanged += Mosaic_OnMosaicChanged;
}
示例9: ReadNodes
public static XmlNode[] ReadNodes(XmlReader xmlReader)
{
if (xmlReader == null)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("xmlReader");
XmlDocument doc = new XmlDocument();
List<XmlNode> nodeList = new List<XmlNode>();
if (xmlReader.MoveToFirstAttribute())
{
do
{
if (IsValidAttribute(xmlReader))
{
XmlNode node = doc.ReadNode(xmlReader);
if (node == null)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.GetString(SR.UnexpectedEndOfFile)));
nodeList.Add(node);
}
} while (xmlReader.MoveToNextAttribute());
}
xmlReader.MoveToElement();
if (!xmlReader.IsEmptyElement)
{
int startDepth = xmlReader.Depth;
xmlReader.Read();
while (xmlReader.Depth > startDepth && xmlReader.NodeType != XmlNodeType.EndElement)
{
XmlNode node = doc.ReadNode(xmlReader);
if (node == null)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.GetString(SR.UnexpectedEndOfFile)));
nodeList.Add(node);
}
}
return nodeList.ToArray();
}
示例10: PolicySetIdReferenceElementReadWrite
/// <summary>
/// Creates a policy set id reference using the XmlReader instance provided.
/// </summary>
/// <param name="reader">The XmlReader instance positioned at the "PolicySetIdReference"
/// node</param>
/// <param name="schemaVersion">The version of the schema that will be used to validate.</param>
public PolicySetIdReferenceElementReadWrite(XmlReader reader, XacmlVersion schemaVersion)
: base(XacmlSchema.Policy, schemaVersion)
{
if (reader == null) throw new ArgumentNullException("reader");
if (reader.LocalName == Consts.Schema1.PolicySetIdReferenceElement.PolicySetIdReference &&
ValidateSchema(reader, schemaVersion))
{
if (reader.HasAttributes)
{
// Load all the attributes
while (reader.MoveToNextAttribute())
{
if (reader.LocalName == Consts.Schema2.PolicyReferenceElement.Version)
{
_version = reader.GetAttribute(Consts.Schema2.PolicyReferenceElement.Version);
}
else if (reader.LocalName == Consts.Schema2.PolicyReferenceElement.EarliestVersion)
{
_earliestVersion = reader.GetAttribute(Consts.Schema2.PolicyReferenceElement.EarliestVersion);
}
else if (reader.LocalName == Consts.Schema2.PolicyReferenceElement.LatestVersion)
{
_latestVersion = reader.GetAttribute(Consts.Schema2.PolicyReferenceElement.LatestVersion);
}
}
reader.MoveToElement();
}
_policySetIdReference = reader.ReadElementString();
}
else
{
throw new Exception(string.Format(Properties.Resource.exc_invalid_node_name, reader.LocalName));
}
}
示例11: ReadXml
public override void ReadXml(XmlReader reader)
{
while (reader.MoveToNextAttribute())
if (!TryReadXmlAttribute(reader))
MapXmlReader.HandleUnexpectedAttribute(reader.LocalName);
reader.MoveToElement();
if (!reader.IsEmptyElement)
{
var isElsePresent = false;
reader.Read();
while (reader.MoveToContent() != XmlNodeType.EndElement)
if (reader.IsStartElement(When.ElementName) && !isElsePresent)
{
var when = new When();
Nodes.Add(when);
when.ReadXml(reader);
}
else if (reader.IsStartElement(Else.ElementName))
{
var elseNode = new Else();
Nodes.Add(elseNode);
elseNode.ReadXml(reader);
isElsePresent = true;
}
else MapXmlReader.HandleUnexpectedElement(reader.LocalName);
}
reader.Read();
}
示例12: ReadXml
public void ReadXml(XmlReader reader)
{
base.ReadXmlAttributes(reader);
reader.MoveToElement();
bool empty = reader.IsEmptyElement;
reader.ReadStartElement(Xml.TestSuite);
if (!empty)
{
reader.ConsumeUntilFirst(XmlReaderHelper.ElementFilter);
while (reader.NodeType == XmlNodeType.Element)
{
if (reader.Name == Xml.TestSuite)
{
new TestSuite(null, this).ReadXml(reader);
}
else if (reader.Name == TestCase.Xml.TestCase)
{
new TestCase(null, this).ReadXml(reader);
}
reader.ConsumeUntilFirst(XmlReaderHelper.ElementFilter);
}
reader.ReadEndElement();
}
}
示例13: GetFeed
public static IFeed GetFeed(Uri url, XmlReader reader) {
reader.MoveToContent();
string language = string.Empty;
FeedType feedType;
string namespaceUri = reader.NamespaceURI;
if(reader.LocalName.Equals("RDF") &&
reader.NamespaceURI.Equals("http://www.w3.org/1999/02/22-rdf-syntax-ns#")) {
feedType = FeedType.Rdf;
reader.Read();
reader.MoveToContent();
} else if(reader.LocalName.Equals("rss")) {
feedType = FeedType.Rss;
do {
reader.Read();
reader.MoveToContent();
} while(!reader.LocalName.Equals("channel") && !reader.LocalName.Equals("rss"));
} else if(reader.NamespaceURI.Equals("http://purl.org/atom/ns#") && reader.LocalName.Equals("feed")) {
if(reader.MoveToAttribute("version") && reader.Value.Equals("0.3")) {
feedType = FeedType.Atom;
language = reader.XmlLang;
reader.MoveToElement();
} else {
throw new ApplicationException(string.Format("Unsupported Atom Version {0}", reader.Value));
}
} else if(reader.NamespaceURI.Equals("http://www.w3.org/2005/Atom") && reader.LocalName.Equals("feed")) {
feedType = FeedType.Atom;
language = reader.XmlLang;
} else {
throw new ApplicationException("Unknown Xml Dialect");
}
return PopulateFeed(url, reader, namespaceUri, feedType, language);
}
示例14: ProcessAttributes
private void ProcessAttributes(XmlReader xmlReader, IReqIfParserCallbackReceiver callbackReceiver)
{
while (xmlReader.MoveToNextAttribute())
{
callbackReceiver.ProcessAttribute(xmlReader.Name, xmlReader.Value);
}
xmlReader.MoveToElement();
}
示例15: ReadAttributes
private static void ReadAttributes(ZXmlNode Node, XmlReader rd)
{
for (int i = 0; i < rd.AttributeCount; i++)
{
rd.MoveToAttribute(i);
Node.Attributes.Add(rd.Name, rd.Value);
}
rd.MoveToElement();
}