/// <summary> /// reads the xml file using elment based approach /// </summary> /// <param name="element">element to be read</param> private void ReadElement(Element element) { //-----read all attributes if (_reader.HasAttributes) { //-----add all the attributes while (_reader.MoveToNextAttribute()) { if (!element.Attributes.ContainsKey(_reader.Name)) { element.Attributes.Add(_reader.Name, _reader.Value); } } //-----invoke attribute callback if (OnAttributesRead != null) { OnAttributesRead.Invoke(element); } _reader.MoveToElement(); } //-----read elements content if (!_reader.IsEmptyElement) { int depth = _reader.Depth; while (_reader.Read()) { //-----read child elements if (_reader.NodeType == XmlNodeType.Element) { Element subElement = new Element() { Parent = element, Name = _reader.Name }; ReadElement(subElement); } //-----read text content else if (_reader.NodeType == XmlNodeType.Text) { element.Value = _reader.Value; } //-----end element reached, so break if its the current one else if (_reader.NodeType == XmlNodeType.EndElement) { if (_reader.Depth == depth) { if (OnElementRead != null) { OnElementRead.Invoke(element); } break; } } } } else if (OnElementRead != null) { OnElementRead.Invoke(element); } }
/// <summary> /// Generates an object from its XML representation. /// </summary> /// <param name="reader">The <see cref="T:System.Xml.XmlReader"/> stream from which the object is deserialized.</param> public void ReadXml(System.Xml.XmlReader reader) { try { _ConsistencyMap.Clear(); reader.Read(); while (reader.NodeType != XmlNodeType.EndElement) { if (reader.Name != "ConsistencyCheckRegion") { Logger.LogError("The 'ConsistencyCheckRegion' element is missing"); } reader.MoveToNextAttribute(); if (reader.Name != "Region") { Logger.LogError("The 'Region' attribute is missing"); } string region = reader.Value; reader.Read(); Dictionary <ConsistencyType, bool> dictType = new Dictionary <ConsistencyType, bool>(); while (reader.NodeType != XmlNodeType.EndElement) { if (reader.Name != "Consistency") { Logger.LogError("The 'ConsistencyCheckRegion' element is missing"); } reader.MoveToNextAttribute(); if (reader.Name != "Type") { Logger.LogError("The 'Type' attribute is missing"); } string type = reader.Value; reader.MoveToNextAttribute(); if (reader.Name != "Value") { Logger.LogError("The 'Value' attribute is missing"); } string value = reader.Value; ConsistencyType consType = (ConsistencyType)Enum.Parse(typeof(ConsistencyType), type, false); dictType[consType] = Convert.ToBoolean(value); reader.Read(); } ConsistencyCheckRegion consRegion = (ConsistencyCheckRegion)Enum.Parse(typeof(ConsistencyCheckRegion), region, false); _ConsistencyMap[consRegion] = dictType; reader.Read(); } reader.Read(); } catch (Exception ex) { Logger.LogCritical("ReadXml() throws an exception: ", ex); } }
void IFlickrParsable.Load(XmlReader reader) { if (!(reader.LocalName != "photos")) ; while (reader.MoveToNextAttribute()) { switch (reader.LocalName) { case "total": this.Total = string.IsNullOrEmpty(reader.Value) ? 0 : int.Parse(reader.Value, (IFormatProvider) CultureInfo.InvariantCulture); continue; case "perpage": case "per_page": this.PerPage = string.IsNullOrEmpty(reader.Value) ? 0 : int.Parse(reader.Value, (IFormatProvider) CultureInfo.InvariantCulture); continue; case "page": this.Page = string.IsNullOrEmpty(reader.Value) ? 0 : int.Parse(reader.Value, (IFormatProvider) CultureInfo.InvariantCulture); continue; case "pages": this.Pages = string.IsNullOrEmpty(reader.Value) ? 0 : int.Parse(reader.Value, (IFormatProvider) CultureInfo.InvariantCulture); continue; default: continue; } } reader.Read(); while (reader.LocalName == "photo") { Photo photo = new Photo(); photo.Load(reader); if (!string.IsNullOrEmpty(photo.PhotoId)) this.Add(photo); } reader.Skip(); }
void IFlickrParsable.Load(XmlReader reader) { while (reader.MoveToNextAttribute()) { switch (reader.LocalName) { case "usage": Usage = reader.ReadContentAsInt(); break; case "predicate": PredicateName = reader.Value; break; case "namespace": NamespaceName = reader.Value; break; case "first_added": DateFirstAdded = UtilityMethods.UnixTimestampToDate(reader.Value); break; case "last_added": DateLastUsed = UtilityMethods.UnixTimestampToDate(reader.Value); break; } } reader.Read(); if (reader.NodeType == XmlNodeType.Text) ValueText = reader.ReadContentAsString(); reader.Read(); }
public void ReadXml(XmlReader reader) { var isEmpty = reader.IsEmptyElement; if (reader.HasAttributes) { for (var i = 0; i < reader.AttributeCount; i++) { reader.MoveToNextAttribute(); if (reader.NamespaceURI == "") { if (reader.LocalName == "type") { Type = reader.Value; } else { AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value); } } } } reader.ReadStartElement(); if (!isEmpty) { DescriptionText = reader.ReadContentAsString(); } reader.ReadEndElement(); }
void IFlickrParsable.Load(XmlReader reader) { while (reader.MoveToNextAttribute()) { switch (reader.LocalName) { case "usage": Usage = reader.ReadContentAsInt(); break; case "predicate": PredicateName = reader.Value; break; case "namespace": NamespaceName = reader.Value; break; } } reader.Read(); if (reader.NodeType == XmlNodeType.Text) PairName = reader.ReadContentAsString(); reader.Read(); }
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(); }
void IFlickrParsable.Load(XmlReader reader) { while (reader.MoveToNextAttribute()) { switch (reader.LocalName) { case "nsid": case "id": this.GroupId = reader.Value; continue; case "name": this.GroupName = reader.Value; continue; case "admin": this.IsAdmin = reader.Value == "1"; continue; case "privacy": this.Privacy = (PoolPrivacy) Enum.Parse(typeof (PoolPrivacy), reader.Value, true); continue; case "iconserver": this.IconServer = reader.Value; continue; case "iconfarm": this.IconFarm = reader.Value; continue; case "photos": this.Photos = long.Parse(reader.Value, NumberStyles.Any, (IFormatProvider) NumberFormatInfo.InvariantInfo); continue; default: continue; } } reader.Read(); }
void IFlickrParsable.Load(XmlReader reader) { Load(reader, false); if (reader.LocalName != "stats") { UtilityMethods.CheckParsingException(reader); } while (reader.MoveToNextAttribute()) { switch (reader.LocalName) { case "views": StatViews = int.Parse(reader.Value, NumberFormatInfo.InvariantInfo); break; case "comments": StatComments = int.Parse(reader.Value, NumberFormatInfo.InvariantInfo); break; case "favorites": StatFavorites = int.Parse(reader.Value, NumberFormatInfo.InvariantInfo); break; default: UtilityMethods.CheckParsingException(reader); break; } } reader.Read(); if (reader.LocalName == "description") Description = reader.ReadElementContentAsString(); reader.Skip(); }
void IFlickrParsable.Load(XmlReader reader) { if (reader.LocalName != "blog") UtilityMethods.CheckParsingException(reader); while (reader.MoveToNextAttribute()) { switch (reader.LocalName) { case "id": BlogId = reader.Value; break; case "name": BlogName = reader.Value; break; case "url": BlogUrl = reader.Value; break; case "needspassword": NeedsPassword = reader.Value == "1"; break; case "service": Service = reader.Value; break; default: UtilityMethods.CheckParsingException(reader); break; } } }
void IFlickrParsable.Load(XmlReader reader) { if (reader.LocalName != "set") UtilityMethods.CheckParsingException(reader); while (reader.MoveToNextAttribute()) { switch (reader.LocalName) { case "id": SetId = reader.Value; break; case "title": Title = reader.Value; break; case "description": Description = reader.Value; break; default: UtilityMethods.CheckParsingException(reader); break; } } reader.Skip(); }
/// <summary>Initializes a new instance of RssCloud</summary> public RssCloud(System.Xml.XmlReader xmlTextReader) { if (!xmlTextReader.HasAttributes) { return; } // System.Reflection.PropertyInfo propertyInfo = null; // while (xmlTextReader.MoveToNextAttribute()) { // find related property by name propertyInfo = GetType().GetProperty(xmlTextReader.Name, System.Reflection.BindingFlags.IgnoreCase | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance); if (propertyInfo != null) { // Protocol enum needs some conversion before the typeconverter can set the values that contains - char if (propertyInfo.Name == "Protocol") { propertyInfo.SetValue(this, System.ComponentModel.TypeDescriptor.GetConverter(propertyInfo.PropertyType).ConvertFromString(xmlTextReader.ReadInnerXml().Trim().Replace("-", "")), null); } else { XmlSerializationUtil.DecodeXmlTextReaderValue(this, xmlTextReader); } } } }
public virtual void ReadXml(System.Xml.XmlReader reader) { if (reader.ReadToDescendant("WriteAttributes") == false) { throw new MyException("Could not find the end of WriteAttributes"); } //Console.WriteLine("After one ReadToDescendant Name = {0}", reader.Name); if (reader.HasAttributes) { int attribCount = 0; while (reader.MoveToNextAttribute()) { attribCount++; } //Console.WriteLine("attribCount = {0}", attribCount); if (attribCount != 3) { throw new MyException(String.Format("XmlReader says this node has no elements {0} {1} and I expect 3", reader.Name, reader.NodeType)); } } else { throw new MyException(String.Format("XmlReader says this node has no elements {0} {1} and I expect 3", reader.Name, reader.NodeType)); } reader.MoveToElement(); // back at WriteAttributes }
void IFlickrParsable.Load(XmlReader reader) { while (reader.MoveToNextAttribute()) { switch (reader.LocalName) { case "id": PhotoId = reader.Value; break; case "ispublic": IsPublic = reader.Value == "1"; break; case "iscontact": IsContact = reader.Value == "1"; break; case "isfamily": IsFamily = reader.Value == "1"; break; case "isfriend": IsFriend = reader.Value == "1"; break; } } reader.Read(); }
void IFlickrParsable.Load(XmlReader reader) { if (!(reader.LocalName != "blog")) ; while (reader.MoveToNextAttribute()) { switch (reader.LocalName) { case "id": this.BlogId = reader.Value; continue; case "name": this.BlogName = reader.Value; continue; case "url": this.BlogUrl = reader.Value; continue; case "needspassword": this.NeedsPassword = reader.Value == "1"; continue; case "service": this.Service = reader.Value; continue; default: continue; } } }
/// <summary> /// Creates an instance of the AttributeValue class using the XmlReader and the name of the node that /// defines the AttributeValue. /// </summary> /// <param name="reader">The XmlReader positioned at the node AttributeValue.</param> /// <param name="schemaVersion">The version of the schema that was used to validate.</param> public AttributeValueElementReadWrite(XmlReader reader, XacmlVersion schemaVersion) : base(XacmlSchema.Policy, schemaVersion) { if (reader == null) throw new ArgumentNullException("reader"); if (reader.LocalName == Consts.Schema1.AttributeValueElement.AttributeValue && 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); } } reader.MoveToElement(); } // Load the node contents _contents = reader.ReadInnerXml(); } else { throw new Exception(string.Format(Properties.Resource.exc_invalid_node_name, reader.LocalName)); } }
void IFlickrParsable.Load(XmlReader reader) { if (reader.LocalName != "referrer") UtilityMethods.CheckParsingException(reader); while (reader.MoveToNextAttribute()) { switch (reader.LocalName) { case "url": Url = reader.Value; break; case "searchterm": SearchTerm = reader.Value; break; case "views": Views = int.Parse(reader.Value, NumberFormatInfo.InvariantInfo); break; default: UtilityMethods.CheckParsingException(reader); break; } } reader.Skip(); }
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); }
void IFlickrParsable.Load(XmlReader reader) { while (reader.MoveToNextAttribute()) { switch (reader.LocalName) { case "nsid": GroupId = reader.Value; break; case "name": GroupName = reader.Value; break; case "admin": IsAdmin = reader.Value == "1"; break; case "eighteenplus": EighteenPlus = reader.Value == "1"; break; case "invitation_only": InvitationOnly = reader.Value == "1"; break; default: UtilityMethods.CheckParsingException(reader); break; } } reader.Read(); }
/// <summary> /// XMLの読み込みを行います。 /// </summary> /// <param name="reader"></param> public void ReadXml(XmlReader reader) { bool isEmpty = reader.IsEmptyElement; if (reader.HasAttributes) { for (int i = 0; i < reader.AttributeCount; i++) { reader.MoveToNextAttribute(); if (!ReadXmlAttribute( reader.NamespaceURI, reader.LocalName, reader.Value)) { AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value); } } } reader.ReadStartElement(); if (!isEmpty) { while (reader.IsStartElement()) { XElement elment = (XElement)XElement.ReadFrom(reader); if (!ReadXmlElement(elment)) ElementExtensions.Add(elment); } reader.ReadEndElement(); } }
public FlatXml Parse(XmlReader reader) { var nodes = new SortedSet<FlatXmlNode>(); var position = 0; while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: var element = new FlatXmlNode {Name = reader.Name, Depth = reader.Depth, Position = position}; nodes.Add(element); if (reader.HasAttributes) { while (reader.MoveToNextAttribute()) { position += 1; var attribute = new FlatXmlNode {Name = reader.Name, Value = reader.Value, Position = position, Depth = reader.Depth}; nodes.Add(attribute); } } break; case XmlNodeType.Text: var t = new FlatXmlNode {Value = reader.Value, Depth = reader.Depth, Position = position}; nodes.Add(t); break; } position += 1; } return new FlatXml(nodes); }
/// <summary> /// return a TreeNode that is the root of a tree representing this Element node with descendants /// </summary> /// <param name="xmlDoc"></param> /// <returns></returns> private TreeNode getTreeRootedAtElementNode(XmlReader xmlDoc) { TreeNode MainTreeRoot = getSingleNode(xmlDoc); TreeNode Attributes = new TreeNode(); Attributes.Text = "<Attributes>"; while (xmlDoc.MoveToNextAttribute()) { Attributes.Nodes.Add(getSingleNode(xmlDoc)); } MainTreeRoot.Nodes.Add(Attributes); xmlDoc.Read(); while(!xmlDoc.EOF) { if(xmlDoc.NodeType == XmlNodeType.Element) { using (XmlReader childElement = xmlDoc.ReadSubtree()) { childElement.Read(); MainTreeRoot.Nodes.Add(getTreeRootedAtElementNode(childElement)); } } else if(xmlDoc.NodeType == XmlNodeType.EndElement) { return MainTreeRoot; } else { MainTreeRoot.Nodes.Add(getSingleNode(xmlDoc)); } xmlDoc.Read(); } return MainTreeRoot; }
/// <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 == PolicySchema1.ObligationElement.AttributeAssignment && ValidateSchema( reader, schemaVersion ) ) { if( reader.HasAttributes ) { // Load all the attributes while( reader.MoveToNextAttribute() ) { if( reader.LocalName == PolicySchema1.AttributeValueElement.DataType ) { _dataType = reader.GetAttribute( PolicySchema1.AttributeValueElement.DataType ); } else if( reader.LocalName == PolicySchema1.AttributeAssignmentElement.AttributeId ) { _attributeId = reader.GetAttribute( PolicySchema1.AttributeAssignmentElement.AttributeId ); } } reader.MoveToElement(); } // Load the node contents _contents = reader.ReadInnerXml(); } else { throw new Exception( Resource.ResourceManager[ Resource.MessageKey.exc_invalid_node_name, reader.LocalName ] ); } }
public virtual void ReadXml(XmlReader reader) { reader.MoveToContent(); if (reader.HasAttributes) while (reader.MoveToNextAttribute()) AttributeWasRead(reader.Name, reader.Value); AllAttributesRead(); var isEmpty = reader.IsEmptyElement; if (!isEmpty) { while (reader.Read()) { var nodeType = reader.NodeType; switch (nodeType) { case XmlNodeType.Text: var content = reader.ReadContentAsString(); ContentWasRead(string.Empty, content); break; case XmlNodeType.Element: var name = reader.Name; ProcessElement(name, reader); break; } } } }
void IFlickrParsable.Load(System.Xml.XmlReader reader) { if (reader.LocalName != "service") { UtilityMethods.CheckParsingException(reader); } while (reader.MoveToNextAttribute()) { switch (reader.LocalName) { case "id": Id = reader.Value; break; default: UtilityMethods.CheckParsingException(reader); break; } } reader.Read(); Name = reader.ReadContentAsString(); reader.Skip(); }
void IFlickrParsable.Load(XmlReader reader) { if (!(reader.LocalName != "tag")) ; while (reader.MoveToNextAttribute()) { switch (reader.LocalName) { case "id": this.TagId = reader.Value; continue; case "author": this.AuthorId = reader.Value; continue; case "authorname": this.AuthorName = reader.Value; continue; case "raw": this.Raw = reader.Value; continue; case "machine_tag": this.IsMachineTag = reader.Value == "1"; continue; default: continue; } } reader.Read(); this.TagText = reader.ReadContentAsString(); reader.Skip(); }
public static EsriEnvelope ProcessEnvelopeNode(XmlReader envelopeNode) { string realVal; EsriEnvelope env = new EsriEnvelope(); while (envelopeNode.MoveToNextAttribute()) { // international numbers realVal = envelopeNode.Value.Replace(',', '.'); switch (envelopeNode.Name) { case "maxx": env.maxX = double.Parse(realVal); break; case "maxy": env.maxY = double.Parse(realVal); break; case "minx": env.minX = double.Parse(realVal); break; case "miny": env.minY = double.Parse(realVal); break; } } return env; }
void IFlickrParsable.Load(XmlReader reader) { if (reader.LocalName != "place_type") UtilityMethods.CheckParsingException(reader); while (reader.MoveToNextAttribute()) { switch (reader.LocalName) { case "place_type_id": case "id": Id = reader.ReadContentAsInt(); break; default: UtilityMethods.CheckParsingException(reader); break; } } reader.Read(); Name = reader.ReadContentAsString(); reader.Skip(); }
void processElement(XmlReader reader) { string path = ""; string label = ""; string labelValue = ""; string[] values = null; bool ground = false; PointF transform; if (!reader.LocalName.Contains ("path") || !reader.HasAttributes) return; while (reader.MoveToNextAttribute()) { switch (reader.LocalName) { case "d": path = reader.Value; values = path.Split(' '); break; case "label": if (reader.Value.Contains("ground") ) { ground = true; } break; case "transform": break; } Console.WriteLine (reader.LocalName); Console.WriteLine (reader.Value); } if (ground) { // Clear the list in case we are loading a new level Terrain.Vertices.Clear(); // Loop through our values and create Vertices for(int i = 1; i < values.Length; i++ ) { if (!values[i].Contains('M')){ var points = values[i].Split(','); float X = float.Parse(points[0]); float Y = float.Parse(points[1]); if (values[i].Contains('l') ){ // LineTo // TODO } else if (values[i].Contains('z')){ // Close the Path // TODO } else{ // Normal Point Terrain.Vertices.Add(new Vector2(X,Y ) ); } Console.WriteLine("{0},{1}", X, Y ); } } } }
void IFlickrParsable.Load(XmlReader reader) { while (reader.MoveToNextAttribute()) { switch (reader.LocalName) { case "id": PhotoId = reader.Value; break; case "ispublic": IsPublic = reader.Value == "1"; break; case "isfamily": IsFamily = reader.Value == "1"; break; case "isfriend": IsFriend = reader.Value == "1"; break; case "permcomment": PermissionComment = (PermissionComment)Enum.Parse(typeof(PermissionComment), reader.Value, true); break; case "permaddmeta": PermissionAddMeta = (PermissionAddMeta)Enum.Parse(typeof(PermissionAddMeta), reader.Value, true); break; default: UtilityMethods.CheckParsingException(reader); break; } } reader.Read(); }
void IFlickrParsable.Load(XmlReader reader) { while (reader.MoveToNextAttribute()) { switch (reader.LocalName) { case "id": this.LicenseId = (LicenseType) reader.ReadContentAsInt(); continue; case "name": this.LicenseName = reader.Value; continue; case "url": if (!string.IsNullOrEmpty(reader.Value)) { this.LicenseUrl = reader.Value; continue; } else continue; default: continue; } } reader.Read(); }
void IFlickrParsable.Load(XmlReader reader) { if (reader.LocalName != "user") UtilityMethods.CheckParsingException(reader); while (reader.MoveToNextAttribute()) { switch (reader.LocalName) { case "nsid": case "id": UserId = reader.Value; break; case "username": UserName = reader.Value; break; case "fullname": FullName = reader.Value; break; default: UtilityMethods.CheckParsingException(reader); break; } } reader.Read(); if (reader.NodeType != XmlNodeType.EndElement) { UserName = reader.ReadElementContentAsString(); reader.Skip(); } }
public void ReadXml(XmlReader reader) { bool isEmpty = reader.IsEmptyElement; if (reader.HasAttributes) { for (int i = 0; i < reader.AttributeCount; i++) { reader.MoveToNextAttribute(); if (reader.NamespaceURI == "") { if (reader.LocalName == "state") { State = reader.Value; } else { AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value); } } } } reader.ReadStartElement(); AddElementExtensions(reader, isEmpty); }
private void LoadScenario(XmlReader reader, Scenario scenario) { while (!reader.EOF && reader.NodeType != XmlNodeType.EndElement) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "Stack") { var stack = new Stack(); scenario.Stacks[reader.GetAttribute("name")] = stack; var stackAttributes = new Dictionary<string, string>(); if (reader.MoveToFirstAttribute()) { for (; ; ) { if (reader.Name != "name") stackAttributes.Add(reader.Name, reader.Value); if (!reader.MoveToNextAttribute()) break; } reader.MoveToElement(); } reader.ReadStartElement("Stack"); LoadStack(reader, stack); reader.ReadEndElement(); foreach (var attr in stackAttributes) _stackDecorator[attr.Key](stack, attr.Value); } else { reader.Read(); } } }
void IFlickrParsable.Load(XmlReader reader) { while (reader.MoveToNextAttribute()) { switch (reader.LocalName) { case "label": this.Label = reader.Value; continue; case "width": this.Width = reader.ReadContentAsInt(); continue; case "height": this.Height = reader.ReadContentAsInt(); continue; case "source": this.Source = reader.Value; continue; case "url": this.Url = reader.Value; continue; case "media": this.MediaType = reader.Value == "photo" ? MediaType.Photos : MediaType.Videos; continue; default: continue; } } reader.Read(); }
/// <summary>Initializes a new instance of RssEnclosure</summary> public RssEnclosure(System.Xml.XmlReader xmlTextReader) { System.Diagnostics.Debug.Assert(xmlTextReader.HasAttributes); // while (xmlTextReader.MoveToNextAttribute()) { XmlSerializationUtil.DecodeXmlTextReaderValue(this, xmlTextReader); } }
private static LiteXmlElement ParseXmlElement(XmlTextReader xmlReader) { var xmlElement = new LiteXmlElement(xmlReader.Name); var isEmptyElement = xmlReader.IsEmptyElement; if (xmlReader.HasAttributes) { while (xmlReader.MoveToNextAttribute()) { xmlElement.Attributes[xmlReader.Name] = xmlReader.Value; } } if (isEmptyElement) { return(xmlElement.IsEmpty()? null: xmlElement); } while (xmlReader.Read()) { //we will read till an end tag is observed switch (xmlReader.NodeType) { case XmlNodeType.Element: // The node is an element. var child = ParseXmlElement(xmlReader); if (child != null) { xmlElement.Children.Add(child); } break; case XmlNodeType.Text: if (!string.IsNullOrEmpty(xmlReader.Value)) { xmlElement.StringValues.Add(xmlReader.Value); } break; case XmlNodeType.EndElement: //Display the end of the element. if (xmlReader.Name == xmlElement.Name) { return(xmlElement.IsEmpty()? null: xmlElement); } Console.WriteLine("WARNING!! encountered unexpected endElement tag:" + xmlReader.Name); break; } } return(null); }
/// <summary>Initializes a new instance of RssGuid</summary> public RssGuid(System.Xml.XmlReader xmlTextReader) : this() { bool emptyElement = xmlTextReader.IsEmptyElement; while (xmlTextReader.MoveToNextAttribute()) { XmlSerializationUtil.DecodeXmlTextReaderValue(this, xmlTextReader); } if (emptyElement) { return; } // xmlTextReader.MoveToElement(); XmlSerializationUtil.DecodeXmlTextReaderValue(this, this.GetType().GetProperty("Value"), xmlTextReader); }
public void ReadXml(System.Xml.XmlReader reader) { bool isEmpty = reader.IsEmptyElement; if (reader.HasAttributes) { for (int i = 0; i < reader.AttributeCount; i++) { reader.MoveToNextAttribute(); if (reader.NamespaceURI == "") { if (reader.LocalName == "ref") { this.Ref = reader.Value; } else if (reader.LocalName == "href") { this.Href = new Uri(reader.Value); } else if (reader.LocalName == "source") { this.Source = new Uri(reader.Value); } else if (reader.LocalName == "type") { this.MediaType = reader.Value; } else { this.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value); } } } } reader.ReadStartElement(); if (!isEmpty) { while (reader.IsStartElement()) { ElementExtensions.Add((XElement)XElement.ReadFrom(reader)); } reader.ReadEndElement(); } }
public bool MoveNext() { if (!_complete) { switch (_reader.NodeType) { case XmlNodeType.Attribute: var result = _reader.MoveToNextAttribute(); _complete = !result; return(result); default: return(_reader.MoveToFirstAttribute()); } } return(false); }
void IFlickrParsable.Load(System.Xml.XmlReader reader) { if (reader.LocalName != "contacts") { UtilityMethods.CheckParsingException(reader); } while (reader.MoveToNextAttribute()) { switch (reader.LocalName) { case "page": Page = int.Parse(reader.Value, System.Globalization.NumberFormatInfo.InvariantInfo); break; case "total": Total = int.Parse(reader.Value, System.Globalization.NumberFormatInfo.InvariantInfo); break; case "pages": Pages = int.Parse(reader.Value, System.Globalization.NumberFormatInfo.InvariantInfo); break; case "per_page": case "perpage": PerPage = int.Parse(reader.Value, System.Globalization.NumberFormatInfo.InvariantInfo); break; default: UtilityMethods.CheckParsingException(reader); break; } } reader.Read(); while (reader.LocalName == "contact") { Contact contact = new Contact(); ((IFlickrParsable)contact).Load(reader); Add(contact); } reader.Skip(); }
void ITwentyThreeParsable.Load(System.Xml.XmlReader reader) { if (reader.LocalName != "domains") { UtilityMethods.CheckParsingException(reader); } while (reader.MoveToNextAttribute()) { switch (reader.LocalName) { case "page": Page = int.Parse(reader.Value, System.Globalization.NumberFormatInfo.InvariantInfo); break; case "total": Total = int.Parse(reader.Value, System.Globalization.NumberFormatInfo.InvariantInfo); break; case "pages": Pages = int.Parse(reader.Value, System.Globalization.NumberFormatInfo.InvariantInfo); break; case "perpage": PerPage = int.Parse(reader.Value, System.Globalization.NumberFormatInfo.InvariantInfo); break; default: UtilityMethods.CheckParsingException(reader); break; } } reader.Read(); while (reader.LocalName == "domain") { var domain = new StatDomain(); ((ITwentyThreeParsable)domain).Load(reader); Add(domain); } reader.Skip(); }
public void ReadXml(System.Xml.XmlReader reader) { // Attributes while (reader.MoveToNextAttribute()) { switch (reader.Name) { case XmlAttribute_Name: this.Name = reader.Value; break; } } reader.MoveToContent(); // Element if (!reader.IsEmptyElement) { reader.ReadStartElement(); while (reader.NodeType == System.Xml.XmlNodeType.Element) { switch (reader.Name) { case TableModelCollection.XmlElement_Tag: this.Tables.ReadXml(reader); break; case RelationshipModelCollection.XmlElement_Tag: this.Relationships.ReadXml(reader); break; default: throw new InvalidOperationException(reader.Name); } } reader.ReadEndElement(); } else { reader.Read(); } }
void IFlickrParsable.Load(System.Xml.XmlReader reader) { if (reader.LocalName != "people") { UtilityMethods.CheckParsingException(reader); } while (reader.MoveToNextAttribute()) { switch (reader.LocalName) { case "total": Total = reader.ReadContentAsInt(); break; case "photo_width": PhotoWidth = reader.ReadContentAsInt(); break; case "photo_height": PhotoHeight = reader.ReadContentAsInt(); break; default: UtilityMethods.CheckParsingException(reader); break; } } reader.Read(); while (reader.LocalName == "person") { var item = new PhotoPerson(); ((IFlickrParsable)item).Load(reader); Add(item); } reader.Skip(); }
private bool IsCollection() { var isCollection = false; if (reader.HasAttributes) { var ok = reader.MoveToFirstAttribute(); while (ok) { var name = reader.Name; var attName = name.ChangeCase(TextCase.PascalCase); if (attName.Equals("IsArray")) { isCollection = (reader.Value == "true") || (reader.Value == "1"); break; } ok = reader.MoveToNextAttribute(); } } reader.MoveToElement(); return(isCollection); }
public virtual void ReadXml(System.Xml.XmlReader reader) { if (reader.ReadToDescendant("WriteStartAttribute") == false) { throw new Exception("could not find the start of element WriteStartAttribute"); } //Console.WriteLine("{0}\r\n{1}", reader.Name, reader.NodeType); if (reader.HasAttributes) { int attribCount = 0; while (reader.MoveToNextAttribute()) { attribCount++; } if (attribCount != 2) { throw new MyException(String.Format("expected 2 attributes, but found {0}", attribCount)); } } else { throw new MyException(String.Format("XmlReader says this node has no elements {0} {1} and I expect 1", reader.Name, reader.NodeType)); } }
private XmlNode?LoadNode(bool skipOverWhitespace) { XmlReader r = _reader !; XmlNode? parent = null; XmlElement? element; IXmlSchemaInfo?schemaInfo; do { XmlNode?node; switch (r.NodeType) { case XmlNodeType.Element: bool fEmptyElement = r.IsEmptyElement; element = _doc !.CreateElement(r.Prefix, r.LocalName, r.NamespaceURI); element.IsEmpty = fEmptyElement; if (r.MoveToFirstAttribute()) { XmlAttributeCollection attributes = element.Attributes; do { XmlAttribute attr = LoadAttributeNode(); attributes.Append(attr); // special case for load }while (r.MoveToNextAttribute()); r.MoveToElement(); } // recursively load all children. if (!fEmptyElement) { parent?.AppendChildForLoad(element, _doc); parent = element; continue; } else { schemaInfo = r.SchemaInfo; if (schemaInfo != null) { element.XmlName = _doc.AddXmlName(element.Prefix, element.LocalName, element.NamespaceURI, schemaInfo); } node = element; break; } case XmlNodeType.EndElement: if (parent == null) { return(null); } Debug.Assert(parent.NodeType == XmlNodeType.Element); schemaInfo = r.SchemaInfo; if (schemaInfo != null) { element = parent as XmlElement; if (element != null) { element.XmlName = _doc !.AddXmlName(element.Prefix, element.LocalName, element.NamespaceURI, schemaInfo); } } if (parent.ParentNode == null) { return(parent); } parent = parent.ParentNode; continue; case XmlNodeType.EntityReference: node = LoadEntityReferenceNode(false); break; case XmlNodeType.EndEntity: Debug.Assert(parent == null); return(null); case XmlNodeType.Attribute: node = LoadAttributeNode(); break; case XmlNodeType.Text: node = _doc !.CreateTextNode(r.Value); break; case XmlNodeType.SignificantWhitespace: node = _doc !.CreateSignificantWhitespace(r.Value); break; case XmlNodeType.Whitespace: if (_preserveWhitespace) { node = _doc !.CreateWhitespace(r.Value); break; } else if (parent == null && !skipOverWhitespace) { // if called from LoadEntityReferenceNode, just return null return(null); } else { continue; } case XmlNodeType.CDATA: node = _doc !.CreateCDataSection(r.Value); break; case XmlNodeType.XmlDeclaration: node = LoadDeclarationNode(); break; case XmlNodeType.ProcessingInstruction: node = _doc !.CreateProcessingInstruction(r.Name, r.Value); break; case XmlNodeType.Comment: node = _doc !.CreateComment(r.Value); break; case XmlNodeType.DocumentType: node = LoadDocumentTypeNode(); break; default: throw UnexpectedNodeType(r.NodeType); } Debug.Assert(node != null); if (parent != null) { parent.AppendChildForLoad(node, _doc !); } else { return(node); } }while (r.Read()); // when the reader ended before full subtree is read, return whatever we have created so far if (parent != null) { while (parent.ParentNode != null) { parent = parent.ParentNode; } } return(parent); }
public static List <XmlReadInstructions> AnalyseXmlReader(System.Xml.XmlReader reader, bool globalUniqueColumnNames) { var root = new Node(); var current = root; var resultSets = new Dictionary <string, Node>(); while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: current = current.SubElement(reader.Name); if (reader.HasAttributes) { reader.MoveToFirstAttribute(); do { current.Attribute(reader.Name); } while (reader.MoveToNextAttribute()); reader.MoveToElement(); } if (current.CurrentCount > 1) { string xpath = current.AbsXPath; if (!resultSets.ContainsKey(xpath)) { resultSets[xpath] = current; current.IsRepetetive = true; } } if (reader.IsEmptyElement) { current = current.Parent; } break; case XmlNodeType.Text: if (!String.IsNullOrWhiteSpace(reader.Value)) { current.HasText = true; } break; case XmlNodeType.XmlDeclaration: case XmlNodeType.ProcessingInstruction: case XmlNodeType.Comment: continue; case XmlNodeType.EndElement: current = current.Parent; break; } } // remove repetetive parents. Remains only innermost repetetives foreach (var resultSet in resultSets.Values.ToList()) { var node = resultSet; node = node.Parent; while (node != null && !node.IsRepetetive) { node = node.Parent; } if (node != null) { resultSets.Remove(node.AbsXPath); node.IsRepetetive = false; } } if (!resultSets.Any()) { resultSets["/"] = root; } var res = new List <XmlReadInstructions>(); var addedColumns = new HashSet <string>(); var collectionNames = new HashSet <string>(); foreach (var resultSet in resultSets.Values) { var instruction = new XmlReadInstructions(); instruction.XPath = resultSet.AbsXPath ?? "/"; string collectionName = resultSet.Name; if (collectionNames.Contains(collectionName)) { int index = 2; while (collectionNames.Contains(collectionName + index)) { index++; } collectionName = collectionName + index; } instruction.CollectionName = collectionName; if (!globalUniqueColumnNames) { addedColumns.Clear(); } CollectColumns(instruction, root, addedColumns, resultSet); if (resultSet != root) { CollectColumns(instruction, resultSet, addedColumns, resultSet); } res.Add(instruction); } return(res); }
private void LoadAttributes(System.Xml.XmlReader reader) { while (reader.MoveToNextAttribute()) { switch (reader.LocalName) { case "name": Description = reader.Value; break; case "place_id": PlaceId = reader.Value; break; case "place_url": PlaceUrl = reader.Value; break; case "place_type_id": PlaceType = (PlaceType)reader.ReadContentAsInt(); break; case "place_type": PlaceType = (PlaceType)Enum.Parse(typeof(PlaceType), reader.Value, true); break; case "woeid": WoeId = reader.Value; break; case "woe_name": WoeName = reader.Value; break; case "latitude": Latitude = reader.ReadContentAsDouble(); break; case "longitude": Longitude = reader.ReadContentAsDouble(); break; case "accuracy": Accuracy = (GeoAccuracy)reader.ReadContentAsInt(); break; case "context": Context = (GeoContext)reader.ReadContentAsInt(); break; case "timezone": TimeZone = reader.Value; break; case "has_shapedata": HasShapeData = reader.Value == "1"; break; default: UtilityMethods.CheckParsingException(reader); break; } } reader.Read(); }
public void ReadXml(System.Xml.XmlReader reader, Type payloadType) { GuidConverter guidConverter = new GuidConverter(); if ((reader.NodeType == System.Xml.XmlNodeType.Element) && (reader.LocalName == "entry") && (reader.NamespaceURI == Namespaces.atomNamespace)) { bool reading = true; while (reading) { if (reader.NodeType == System.Xml.XmlNodeType.Element) { switch (reader.LocalName) { case "title": reading = reader.Read(); if (reader.NodeType == System.Xml.XmlNodeType.Text) { this.Title = reader.Value; } break; case "id": reading = reader.Read(); if (reader.NodeType == System.Xml.XmlNodeType.Text) { this.Id = reader.Value; } break; case "uuid": reading = reader.Read(); if (reader.NodeType == System.Xml.XmlNodeType.Text) { string uuidString = reader.Value; this.Uuid = (Guid)guidConverter.ConvertFromString(uuidString); } break; case "httpStatus": reading = reader.Read(); if (reader.NodeType == System.Xml.XmlNodeType.Text) { this.HttpStatusCode = (HttpStatusCode)Enum.Parse(typeof(HttpStatusCode), reader.Value); } break; case "httpMessage": reading = reader.Read(); if (reader.NodeType == System.Xml.XmlNodeType.Text) { this.HttpMessage = reader.Value; } break; case "location": reading = reader.Read(); if (reader.NodeType == System.Xml.XmlNodeType.Text) { this.HttpLocation = reader.Value; } break; case "httpMethod": reading = reader.Read(); if (reader.NodeType == System.Xml.XmlNodeType.Text) { this.HttpMethod = reader.Value; } break; case "payload": System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(payloadType); object obj = serializer.Deserialize(reader); if (obj is PayloadBase) { this.Payload = obj as PayloadBase; } break; case "syncState": System.Xml.Serialization.XmlSerializer syncStateSerializer = new System.Xml.Serialization.XmlSerializer(typeof(SyncState)); object obj1 = syncStateSerializer.Deserialize(reader); if (obj1 is SyncState) { this.SyncState = obj1 as SyncState; } break; case "link": if (reader.HasAttributes) { SyncFeedEntryLink link = new SyncFeedEntryLink(); while (reader.MoveToNextAttribute()) { if (reader.LocalName.Equals("payloadpath", StringComparison.InvariantCultureIgnoreCase)) { link.PayloadPath = reader.Value; } if (reader.LocalName.Equals("rel", StringComparison.InvariantCultureIgnoreCase)) { link.LinkRel = reader.Value; } if (reader.LocalName.Equals("type", StringComparison.InvariantCultureIgnoreCase)) { link.LinkType = reader.Value; } if (reader.LocalName.Equals("title", StringComparison.InvariantCultureIgnoreCase)) { link.Title = reader.Value; } if (reader.LocalName.Equals("uuid", StringComparison.InvariantCultureIgnoreCase)) { link.Uuid = reader.Value; } if (reader.LocalName.Equals("href", StringComparison.InvariantCultureIgnoreCase)) { link.Href = reader.Value; } } this.SyncLinks.Add(link); } break; case "linked": System.Xml.Serialization.XmlSerializer linkedSerializer = new System.Xml.Serialization.XmlSerializer(typeof(LinkedElement)); object linkedObj = linkedSerializer.Deserialize(reader); if (linkedObj is LinkedElement) { this.Linked = linkedObj as LinkedElement; } break; default: reading = reader.Read(); break; } } else { if ((reader.NodeType == System.Xml.XmlNodeType.EndElement) && (reader.LocalName == "entry")) { reading = false; } else { reading = reader.Read(); } } } } }
public virtual void ReadXml(System.Xml.XmlReader reader) { if (reader.ReadToDescendant("WriteAttributeString") == false) { throw new MyException("Could not find the end of WriteAttributeString"); } //Console.WriteLine("AFter 1 reader.NodeType, {0} name {1} depth {2}", reader.NodeType, reader.Name, reader.Depth); if (reader.HasAttributes) { int attribCount = 0; string msg = null; while (reader.MoveToNextAttribute()) { Trace.WriteLine(String.Format("attribute[{0}], localname=\"{1}\" value=\"{2}\" namespaceURI=\"{3}\"", attribCount, reader.LocalName, reader.Value, reader.NamespaceURI)); if (String.IsNullOrEmpty(reader.LocalName)) { continue; } switch (reader.LocalName) { case "attributeName": if (reader.Prefix == null || !reader.Prefix.Equals("abc")) { msg = String.Format("attributeName: reader.Name = {0}, reader.NamespaceURI = {1} reader.Value = {2} reader.Prefix = {3}", reader.Name, reader.NamespaceURI, reader.Value, reader.Prefix); throw new MyException(msg); } break; case "attributeName2": break; case "attributeName3": if (reader.NamespaceURI == null || !reader.NamespaceURI.Equals("myNameSpace3")) { msg = String.Format("attributeName: reader.Name = {0}, reader.NamespaceURI = {1} reader.ReadAttributeValue() = {2} reader.Prefix = {3}", reader.Name, reader.NamespaceURI, reader.Value, reader.Prefix); throw new MyException(msg); } break; default: if (reader.Value != null && reader.Value.Equals("myNameSpace3")) { // this is my namespace declaration, it is OK break; } if (reader.LocalName != null && reader.LocalName.Equals("abc")) { // this is my namespace declaration, it is OK break; } msg = String.Format("DEFAULT LocalName <{0}> \r\n reader.Name = <{1}>, \r\n reader.NamespaceURI = <{2}> \r\n reader.ReadAttributeValue() = {3}", reader.LocalName, reader.Name, reader.NamespaceURI, reader.Value); throw new MyException(msg); } attribCount++; } //Console.WriteLine("attribCount = {0}", attribCount); if (attribCount != 5) { throw new MyException(String.Format("XmlReader says this node {0} {1} has no elements and I expect 4", reader.Name, reader.NodeType)); } } else { throw new MyException(String.Format("XmlReader says this node has no elements {0} {1} and I expect 3", reader.Name, reader.NodeType)); } reader.MoveToElement(); // back at WriteAttributes }
/// <summary> /// Serializes the XML to an instance. /// </summary> /// <param name="reader"></param> void IFlickrParsable.Load(System.Xml.XmlReader reader) { while (reader.MoveToNextAttribute()) { switch (reader.LocalName) { case "name": Description = reader.Value; break; case "place_id": PlaceId = reader.Value; break; case "place_url": PlaceUrl = reader.Value; break; case "place_type_id": PlaceType = (PlaceType)reader.ReadContentAsInt(); break; case "place_type": PlaceType = (PlaceType)Enum.Parse(typeof(PlaceType), reader.Value, true); break; case "woeid": WoeId = reader.Value; break; case "woe_name": WoeName = reader.Value; break; case "latitude": Latitude = reader.ReadContentAsDouble(); break; case "longitude": Longitude = reader.ReadContentAsDouble(); break; case "timezone": TimeZone = reader.Value; break; case "photo_count": PhotoCount = reader.ReadContentAsInt(); break; default: UtilityMethods.CheckParsingException(reader); break; } } reader.Read(); while (reader.NodeType != XmlNodeType.EndElement) { if (reader.NodeType == XmlNodeType.Text) { Description = reader.ReadContentAsString(); } else { switch (reader.LocalName) { default: UtilityMethods.CheckParsingException(reader); break; } } } reader.Read(); }
public override bool MoveToNextAttribute() { return(reader.MoveToNextAttribute()); }
// LoadNodeDirect does not use creator functions on XmlDocument. It is used loading nodes that are children of entity nodes, // because we do not want to let users extend these (if we would allow this, XmlDataDocument would have a problem, because // they do not know that those nodes should not be mapped). It can be also used for an optimized load path when if the // XmlDocument is not extended if XmlDocumentType and XmlDeclaration handling is added. private XmlNode?LoadNodeDirect() { XmlReader r = _reader !; XmlNode? parent = null; do { XmlNode?node; switch (r.NodeType) { case XmlNodeType.Element: bool fEmptyElement = _reader !.IsEmptyElement; XmlElement element = new XmlElement(_reader.Prefix, _reader.LocalName, _reader.NamespaceURI, _doc !); element.IsEmpty = fEmptyElement; if (_reader.MoveToFirstAttribute()) { XmlAttributeCollection attributes = element.Attributes; do { XmlAttribute attr = LoadAttributeNodeDirect(); attributes.Append(attr); // special case for load } while (r.MoveToNextAttribute()); } // recursively load all children. if (!fEmptyElement) { parent !.AppendChildForLoad(element, _doc !); parent = element; continue; } else { node = element; break; } case XmlNodeType.EndElement: Debug.Assert(parent !.NodeType == XmlNodeType.Element); if (parent.ParentNode == null) { return(parent); } parent = parent.ParentNode; continue; case XmlNodeType.EntityReference: node = LoadEntityReferenceNode(true); break; case XmlNodeType.EndEntity: continue; case XmlNodeType.Attribute: node = LoadAttributeNodeDirect(); break; case XmlNodeType.SignificantWhitespace: node = new XmlSignificantWhitespace(_reader !.Value, _doc !); break; case XmlNodeType.Whitespace: if (_preserveWhitespace) { node = new XmlWhitespace(_reader !.Value, _doc !); } else { continue; } break; case XmlNodeType.Text: node = new XmlText(_reader !.Value, _doc !); break; case XmlNodeType.CDATA: node = new XmlCDataSection(_reader !.Value, _doc !); break; case XmlNodeType.ProcessingInstruction: node = new XmlProcessingInstruction(_reader !.Name, _reader.Value, _doc !); break; case XmlNodeType.Comment: node = new XmlComment(_reader !.Value, _doc !); break; default: throw UnexpectedNodeType(_reader !.NodeType); } Debug.Assert(node != null); if (parent != null) { parent.AppendChildForLoad(node, _doc !); } else { return(node); } }while (r.Read()); return(null); }
public string[] ReadXML(string txt, string number) { string[] StrRecivedMessage = new string[2]; int i = 0; System.Xml.XmlReader objXMLReader = System.Xml.XmlReader.Create(new System.IO.StringReader(txt)); string element = string.Empty; string strSMS = string.Empty; string strMessage = string.Empty; string strTmp = string.Empty; bool blnFindNo = false; try { while (objXMLReader.Read()) { switch (objXMLReader.NodeType) { case XmlNodeType.Element: element = objXMLReader.Name; if (objXMLReader.HasAttributes) { while (objXMLReader.MoveToNextAttribute()) { if (element == "batch") { } } } break; case XmlNodeType.Text: if (element == "status") { //i = i; StrRecivedMessage[i] = objXMLReader.Value; } if (element == "time") { i = i + 1; StrRecivedMessage[i] = objXMLReader.Value; break; } break; case XmlNodeType.CDATA: if (element == "destAddr") { if (objXMLReader.Value != "+98" + number.Substring(1)) { continue; } else { blnFindNo = true; } i = i + 1; StrRecivedMessage[i] = objXMLReader.Value; } if (element == "origAddr") { i = i + 1; StrRecivedMessage[i] = objXMLReader.Value; } else if (element == "message") { strTmp = objXMLReader.Value; } break; } } ; return(StrRecivedMessage); } catch (Exception) { throw; } }
public override object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result) { // Create the types Type ivlType = typeof(IVL <>); Type ivlGenericType = ivlType.MakeGenericType(GenericArguments); // Sometimes there can be just a messy, unstructured value inline with this IVL (like in CCDA) so we still need to support that MemoryStream leftOvers = new MemoryStream(); XmlWriter leftoverWriter = XmlWriter.Create(leftOvers); leftoverWriter.WriteStartElement(s.LocalName, s.NamespaceURI); // Create an instance of rto from the rtoType object instance = ivlGenericType.GetConstructor(Type.EmptyTypes).Invoke(null); if (s.MoveToFirstAttribute()) { do { switch (s.LocalName) { case "nullFlavor": ((ANY)instance).NullFlavor = (NullFlavor)Util.FromWireFormat(s.GetAttribute("nullFlavor"), typeof(NullFlavor)); break; case "operator": ivlGenericType.GetProperty("Operator").SetValue(instance, Util.FromWireFormat(s.GetAttribute("operator"), typeof(SetOperator?)), null); break; case "specializationType": if (result.CompatibilityMode == DatatypeFormatterCompatibilityMode.Canadian) { ((ANY)instance).Flavor = s.GetAttribute("specializationType"); } break; default: leftoverWriter.WriteAttributeString(s.Prefix, s.LocalName, s.NamespaceURI, s.Value); break; } } while (s.MoveToNextAttribute()); s.MoveToElement(); } // Get property information PropertyInfo lowProperty = ivlGenericType.GetProperty("Low"), highProperty = ivlGenericType.GetProperty("High"), widthProperty = ivlGenericType.GetProperty("Width"), centerProperty = ivlGenericType.GetProperty("Center"), lowClosedProperty = ivlGenericType.GetProperty("LowClosed"), highClosedProperty = ivlGenericType.GetProperty("HighClosed"), valueProperty = ivlGenericType.GetProperty("Value"); // Now process the elements #region Elements if (!s.IsEmptyElement) { int sDepth = s.Depth; string sName = s.Name; s.Read(); // string Name while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName)) { string oldName = s.Name; // Name try { if (s.NodeType == System.Xml.XmlNodeType.Element && s.LocalName == "low") // low value { if (!String.IsNullOrEmpty(s.GetAttribute("inclusive"))) { lowClosedProperty.SetValue(instance, Util.FromWireFormat(s.GetAttribute("inclusive"), typeof(bool?)), null); } var parseResult = Host.Parse(s, GenericArguments[0]); result.Code = parseResult.Code; result.AddResultDetail(parseResult.Details); lowProperty.SetValue(instance, parseResult.Structure, null); } else if (s.NodeType == System.Xml.XmlNodeType.Element && s.LocalName == "high") // high value { if (!String.IsNullOrEmpty(s.GetAttribute("inclusive"))) { highClosedProperty.SetValue(instance, Util.FromWireFormat(s.GetAttribute("inclusive"), typeof(bool?)), null); } var parseResult = Host.Parse(s, GenericArguments[0]); result.Code = parseResult.Code; result.AddResultDetail(parseResult.Details); highProperty.SetValue(instance, parseResult.Structure, null); } else if (s.NodeType == System.Xml.XmlNodeType.Element && s.LocalName == "center") // center { var parseResult = Host.Parse(s, GenericArguments[0]); result.Code = parseResult.Code; result.AddResultDetail(parseResult.Details); centerProperty.SetValue(instance, parseResult.Structure, null); } else if (s.NodeType == System.Xml.XmlNodeType.Element && s.LocalName == "width") // width { var parseResult = Host.Parse(s, typeof(PQ)); result.Code = parseResult.Code; result.AddResultDetail(parseResult.Details); widthProperty.SetValue(instance, parseResult.Structure, null); } else if (s.NodeType == System.Xml.XmlNodeType.Element) { leftoverWriter.WriteNode(s, true); //result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, s.LocalName, s.NamespaceURI, s.ToString(), null)); } } catch (MessageValidationException e) // Message validation error { result.AddResultDetail(new MARC.Everest.Connectors.ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, e)); } finally { if (s.Name == oldName) { s.Read(); } } } } #endregion // Process any leftovers as Value !!! try { leftoverWriter.WriteEndElement(); leftoverWriter.Flush(); leftOvers.Seek(0, SeekOrigin.Begin); using (XmlReader xr = XmlReader.Create(leftOvers)) { xr.MoveToContent(); if (xr.AttributeCount > 1 || !xr.IsEmptyElement) { bool isNotEmpty = !xr.IsEmptyElement; if (xr.MoveToFirstAttribute()) { do { isNotEmpty |= xr.Prefix != "xmlns" && xr.LocalName != "xmlns" && xr.NamespaceURI != DatatypeFormatter.NS_XSI; } while (!isNotEmpty && xr.MoveToNextAttribute()); } xr.MoveToElement(); if (isNotEmpty) { var baseResult = base.Parse(xr, result); valueProperty.SetValue(instance, Util.FromWireFormat(baseResult, valueProperty.PropertyType), null); } } } } catch { } // Validate base.Validate(instance as ANY, s.LocalName, result); return(instance); }
public DataTable GetProjectTable(string subFolder) { DataTable table = new DataTable(); table.Columns.Add(new DataColumn("TemplateName", System.Type.GetType("System.String"))); table.Columns.Add(new DataColumn("TemplateDescription", System.Type.GetType("System.String"))); table.Columns.Add(new DataColumn("TemplatePath", System.Type.GetType("System.String"))); table.Columns.Add(new DataColumn("TemplateCreateDate", System.Type.GetType("System.String"))); table.Columns.Add(new DataColumn("Name", System.Type.GetType("System.String"))); table.Columns.Add(new DataColumn("Location", System.Type.GetType("System.String"))); table.Columns.Add(new DataColumn("Description", System.Type.GetType("System.String"))); table.Columns.Add(new DataColumn("EpiVersion", System.Type.GetType("System.String"))); table.Columns.Add(new DataColumn("CreateDate", System.Type.GetType("System.String"))); DataRow row; string projectFolderPath = Path.Combine(templatesPath, subFolder); if (Directory.Exists(projectFolderPath) != true) { return(table); } String[] projectTemplates = GetFiles(projectFolderPath, "*.xml;*.eit"); foreach (string path in projectTemplates) { row = table.NewRow(); try { using (System.Xml.XmlReader reader = System.Xml.XmlReader.Create(path)) { while (reader.ReadToFollowing("Template")) { if (reader.MoveToFirstAttribute()) { AddAttributeToProjectTableRow(row, reader); while (reader.MoveToNextAttribute()) { AddAttributeToProjectTableRow(row, reader); } while (reader.ReadToFollowing("Project")) { if (reader.MoveToFirstAttribute()) { if (table.Columns.Contains(reader.Name)) { row[reader.Name] = reader.Value; } while (reader.MoveToNextAttribute()) { if (table.Columns.Contains(reader.Name)) { row[reader.Name] = reader.Value; } } } } row["TemplatePath"] = path; table.Rows.Add(row); } } } } catch {} } return(table); }
public override bool MoveToNextAttribute() { CheckAsync(); return(_coreReader.MoveToNextAttribute()); }