MoveToFirstAttribute() public abstract method

public abstract MoveToFirstAttribute ( ) : bool
return bool
 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();
 }
Beispiel #2
0
 public string GetValue(string key)
 {
     _reader = XmlReader.Create(_configFile);
     _reader.ReadToFollowing(key);
     _reader.MoveToFirstAttribute();
     return _reader.Value;
 }
Beispiel #3
0
        public static bool CheckPerspexRoot(XmlReader reader)
        {
            try
            {
                while (!reader.IsStartElement())
                {
                    reader.Read();
                }
                if (!reader.MoveToFirstAttribute())
                    return false;
                do
                {
                    if (reader.Name == "xmlns")
                    {
                        reader.ReadAttributeValue();
                        return reader.Value.ToLower() == PerspexNamespace;
                    }

                } while (reader.MoveToNextAttribute());
                return false;
            }
            catch
            {
                return false;
            }
        }
        object Read(XmlReader reader, Type type)
        {
            var obj = Activator.CreateInstance(type);

            if (reader.HasAttributes)
            {
                reader.MoveToFirstAttribute();
                do
                {
                    var propertyInfo = type.GetProperty(reader.Name);
                    propertyInfo
                        .SetValue(
                            obj,
                            Convert.ChangeType(reader.Value, propertyInfo.PropertyType)
                        );
                } while (reader.MoveToNextAttribute());
            }

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                    case XmlNodeType.Element:
                        var propertyInfo = type.GetProperty(reader.Name);
                        propertyInfo
                            .SetValue(
                                obj,
                                ReadValue(reader, propertyInfo.PropertyType)
                            );
                        break;
                }
            }

            return obj;
        }
        internal static ClassData Read(XmlReader xmlReader)
        {
            var classData = new ClassData();
            xmlReader.MoveToFirstAttribute();
            do
            {
                if (xmlReader.Name.Length > 0)
                {
                    switch (xmlReader.Name)
                    {
                        case ("typeName"):
                            {
                                classData.TypeName = xmlReader.Value;
                                break;
                            }
                        default:
                            {
                                throw new Exception(string.Format("Un-expected element while parsing xml. Element name='{0}'", xmlReader.Name));
                            }
                    }
                }
            } while (xmlReader.MoveToNextAttribute());
            while (xmlReader.Read())
            {
                if (xmlReader.NodeType == XmlNodeType.EndElement)
                {
                    break;
                }
                if (xmlReader.IsStartElement())
                {
                    switch (xmlReader.Name)
                {
                    case("method"):
                        {
                            var methodData = MethodData.Read(xmlReader);
                            classData.Methods.Add(methodData);
                            break;
                        }
                    case("property"):
                        {
                            var propertyData = PropertyData.Read(xmlReader);
                            classData.Properties.Add(propertyData);
                            break;
                        }
                    case("field"):
                        {
                            var fieldData = FieldData.Read(xmlReader);
                            classData.Fields.Add(fieldData);
                            break;
                        }
                    default:
                        {
                            throw new Exception(string.Format("Un-expected element while parsing xml. Element name='{0}'", xmlReader.Name));
                            }

                }}
            }
            xmlReader.Read();
                return classData;
        }
Beispiel #6
0
        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();
                }
            }
        }
Beispiel #7
0
 private static IEnumerable<string> ReadMedia(XmlReader media)
 {
     while (media.ReadToFollowing("local"))
     {
         media.MoveToFirstAttribute();
         yield return media.ReadContentAsString();
     }
 }
        internal static MethodData Read(XmlReader xmlReader)
        {
            var methodData = new MethodData();
            xmlReader.MoveToFirstAttribute();
            do
            {
                if (xmlReader.Name.Length > 0)
                {
                    switch (xmlReader.Name)
                    {
                        case ("name"):
                            {
                                methodData.Name = xmlReader.Value;
                                break;
                            }
                        default:
                            {
                                throw new Exception(string.Format("Un-expected element while parsing xml. Element name='{0}'", xmlReader.Name));
                            }
                    }
                }
            } while (xmlReader.MoveToNextAttribute());
            while (xmlReader.Read())
            {
                if (xmlReader.NodeType == XmlNodeType.EndElement)
                {
                    break;
                }
                if (xmlReader.IsStartElement())
                {
                    switch (xmlReader.Name)
                    {
                        case ("overloadType"):
                            {
                                var typeData = TypeData.Read(xmlReader);
                                methodData.OverloadTypes.Add(typeData);
                                break;
                            }
                        case ("parameter"):
                            {
                                var parameterData = ParameterData.Read(xmlReader);
                                methodData.Parameters.Add(parameterData);
                                break;
                            }
                        default:
                            {
                                throw new Exception(string.Format("Un-expected element while parsing xml. Element name='{0}'", xmlReader.Name));
                            }

                    }
                }
            }
            xmlReader.Read();
            return methodData;
        }
		public static IfNotStatement Read (XmlReader reader)
		{
			IfNotStatement result = new IfNotStatement ();
			if (reader.MoveToFirstAttribute ()) {
				do {
					result.SetAttribute (reader.LocalName, reader.Value);
				} while (reader.MoveToNextAttribute ());
			}
			result.Children = Node.ReadNodeList (reader, XmlTag);
			return result;
		}
Beispiel #10
0
 public Strand(XmlReader r)
 {
     // The reader is currently positioned at the start of a strand element.
     // r.Name is currently "s"
     r.MoveToFirstAttribute();
     _level = uint.Parse(r.Value);
     _values = K.GetUIntList(r.ReadString());
     // r.Name is the end tag "s" here
     K.ReadToXmlElementTag(r, "s", "strands");
     // r.Name is either the start tag "s" of a new strand
     // or the end tag "strands"
 }
        internal static FieldData Read(XmlReader xmlReader)
        {
            var fieldData = new FieldData();
            xmlReader.MoveToFirstAttribute();
            do
            {
                if (xmlReader.Name.Length > 0)
                {
                    switch (xmlReader.Name)
                    {
                        case ("name"):
                            {
                                fieldData.Name = xmlReader.Value;
                                break;
                            }
                        default:
                            {
                                throw new Exception(string.Format("Un-expected element while parsing xml. Element name='{0}'", xmlReader.Name));
                            
                            }
                    }
                }
            } while (xmlReader.MoveToNextAttribute());
            while (xmlReader.Read())
            {
                if (xmlReader.NodeType == XmlNodeType.EndElement)
                {
                    break;
                }
                if (xmlReader.IsStartElement())
                {
                    switch (xmlReader.Name)
                    {
                        case ("rule"):
                            {
                                var ruleData = RuleData.Read(xmlReader);
                                fieldData.RuleDatas.Add(ruleData);
                                break;
                            }
                        default:
                            {
                                throw new Exception(string.Format("Un-expected element while parsing xml. Element name='{0}'", xmlReader.Name));
                            }

                    }
                }
            }
            xmlReader.Read();
            return fieldData;
        }
        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);
        }
Beispiel #13
0
        public void Update(XmlReader rd)
        {
            Trace.Assert(m_name == rd.Name);
            Trace.Assert(rd.NodeType == XmlNodeType.Element);

            m_count++;

            if (rd.MoveToFirstAttribute())
            {
                do
                {
                    var attrName = rd.Name;
                    if (!m_attributeCounts.ContainsKey(attrName))
                        m_attributeCounts.Add(attrName, 0);

                    m_attributeCounts[attrName] = m_attributeCounts[attrName] + 1;
                } while (rd.MoveToNextAttribute());
            }
        }
 private string ConvertToJsonAttributes(XmlReader xmlReader)
 {
     string result = "";
     if (xmlReader.HasAttributes)
     {
         result = string.Format("{0}\"atributes\" : [\r\n", new string('\t', tabCount));
         xmlReader.MoveToFirstAttribute();
         ++tabCount;
         for (int i = 0; i < xmlReader.AttributeCount; i++)
         {
             result += new string('\t', tabCount) + 
                 string.Format("\"{0}\" : \"{1}\",\r\n", xmlReader.Name, xmlReader.Value);
             xmlReader.MoveToNextAttribute();
         }
         --tabCount;
         result += string.Format("{0}],\r\n", new string('\t', tabCount));
         xmlReader.MoveToElement();
     }
     return result;
 }
Beispiel #15
0
        private static IEnumerable<NodeAttribute> GetAttributes(XmlReader reader)
        {
            var tokens = new List<Pair<string, string>>();

            if (reader.MoveToFirstAttribute())
            {
                do
                {
                    tokens.Add(new Pair<string, string>(reader.Name, reader.Value));

                } while (reader.MoveToNextAttribute());
            }

            reader.MoveToElement();

            for (int i = 0; i < tokens.Count; i++)
            {
                yield return new NodeAttribute(i, tokens[i].First, tokens[i].Second, tokens.Count);
            }
        }
 public static System.Xml.XmlNode[] ReadNodes(XmlReader xmlReader)
 {
     if (xmlReader == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("xmlReader");
     }
     XmlDocument document = new XmlDocument();
     List<System.Xml.XmlNode> list = new List<System.Xml.XmlNode>();
     if (xmlReader.MoveToFirstAttribute())
     {
         do
         {
             if (IsValidAttribute(xmlReader))
             {
                 System.Xml.XmlNode item = document.ReadNode(xmlReader);
                 if (item == null)
                 {
                     throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(System.Runtime.Serialization.SR.GetString("UnexpectedEndOfFile")));
                 }
                 list.Add(item);
             }
         }
         while (xmlReader.MoveToNextAttribute());
     }
     xmlReader.MoveToElement();
     if (!xmlReader.IsEmptyElement)
     {
         int depth = xmlReader.Depth;
         xmlReader.Read();
         while ((xmlReader.Depth > depth) && (xmlReader.NodeType != XmlNodeType.EndElement))
         {
             System.Xml.XmlNode node2 = document.ReadNode(xmlReader);
             if (node2 == null)
             {
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(System.Runtime.Serialization.SR.GetString("UnexpectedEndOfFile")));
             }
             list.Add(node2);
         }
     }
     return list.ToArray();
 }
		public static SwitchStatement Read (XmlReader reader)
		{
			var result = new SwitchStatement ();
			if (reader.MoveToFirstAttribute ()) {
				do {
					result.SetAttribute (reader.LocalName, reader.Value);
				} while (reader.MoveToNextAttribute ());
			}
			XmlReadHelper.ReadList (reader, XmlTag, delegate () {
				switch (reader.LocalName) {
				case "Case":
					result.CaseSections.Add (CaseStatement.Read (reader));
					return true;
				case "Default":
					result.Children = Node.ReadNodeList (reader, "Default");
					return true;
				}
				return false;
			});
			
			return result;
		}
Beispiel #18
0
        public void ReadXml(System.Xml.XmlReader reader)
        {
            if (reader.MoveToFirstAttribute())
            {
                TransactionId    = new Guid(reader.GetAttribute("transactionId"));
                _name            = reader.GetAttribute("name");
                IsolationLevel   = (IsolationLevel)Enum.Parse(typeof(IsolationLevel), reader.GetAttribute("isolationLevel"));
                CreatedOn        = DateTime.Parse(reader.GetAttribute("createdOn"));
                TransactionState = (TransactionState)Enum.Parse(typeof(TransactionState), reader.GetAttribute("transactionState"));

                // Setting the IsStarted property is important so that our checks to see if the
                // Transaction is started are valid.
                IDisposable tx = TransactionManager.Instance.GetTransaction(this);
                if (tx == null)
                {
                    IsStarted = false;
                }
                else
                {
                    IsStarted = true;
                }
            }
        }
Beispiel #19
0
        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);
        }
 internal static TypeData Read(XmlReader xmlReader)
 {
     var typeData = new TypeData();
     xmlReader.MoveToFirstAttribute();
     do
     {
         if (xmlReader.Name.Length > 0)
         {
             switch (xmlReader.Name)
             {
                 case ("typeName"):
                     {
                         typeData.TypeName = xmlReader.Value;
                         break;
                     }
                 default:
                     {
                         throw new Exception(string.Format("Un-expected element while parsing xml. Element name='{0}'", xmlReader.Name));
                     }
             }
         }
     } while (xmlReader.MoveToNextAttribute());
     return typeData;
 }
		// returns remaining attributes to be processed
		Dictionary<string,string> ProcessAttributes (XmlReader r, List<Pair> members)
		{
			var l = members;

			// base (top element)
			if (!xmlbase_done) {
				xmlbase_done = true;
				string xmlbase = r.GetAttribute ("base", XamlLanguage.Xml1998Namespace) ?? r.BaseURI;
				if (xmlbase != null)
					l.Add (new Pair (XamlLanguage.Base, xmlbase));
			}

			var atts = new Dictionary<string,string> ();

			if (r.MoveToFirstAttribute ()) {
				do {
					switch (r.NamespaceURI) {
					case XamlLanguage.Xml1998Namespace:
						switch (r.LocalName) {
						case "base":
							continue; // already processed.
						case "lang":
							l.Add (new Pair (XamlLanguage.Lang, r.Value));
							continue;
						case "space":
							l.Add (new Pair (XamlLanguage.Space, r.Value));
							continue;
						}
						break;
					case XamlLanguage.Xmlns2000Namespace:
						continue;
					case XamlLanguage.Xaml2006Namespace:
						XamlDirective d = FindStandardDirective (r.LocalName, AllowedMemberLocations.Attribute);
						if (d != null) {
							l.Add (new Pair (d, r.Value));
							continue;
						}
						throw new NotSupportedException (String.Format ("Attribute '{0}' is not supported", r.Name));
					default:
						if (r.NamespaceURI == String.Empty) {
							atts.Add (r.Name, r.Value);
							continue;
						}
						// Should we just ignore unknown attribute in XAML namespace or any other namespaces ?
						// Probably yes for compatibility with future version.
						break;
					}
				} while (r.MoveToNextAttribute ());
				r.MoveToElement ();
			}
			return atts;
		}
Beispiel #22
0
		// Reads XmlReader and creates Attribute Node.
		private XmlAttribute ReadAttributeNode (XmlReader reader)
		{
			if (reader.NodeType == XmlNodeType.Element)
				reader.MoveToFirstAttribute ();
			else if (reader.NodeType != XmlNodeType.Attribute)
				throw new InvalidOperationException (MakeReaderErrorMessage ("bad position to read attribute.", reader));
			XmlAttribute attribute = CreateAttribute (reader.Prefix, reader.LocalName, reader.NamespaceURI);
#if NET_2_0
			if (reader.SchemaInfo != null)
				SchemaInfo = reader.SchemaInfo;
#endif
			bool isDefault = reader.IsDefault;

			ReadAttributeNodeValue (reader, attribute);

			if (isDefault)
				attribute.SetDefault ();

			return attribute;
		}
Beispiel #23
0
        private void PopulateNode(WsXmlNode node, WsXmlNode parent, XmlReader reader)
        {
            node.LocalName = reader.LocalName;
            node.NamespaceURI = reader.NamespaceURI;
            node.Prefix = reader.Prefix;
            node.ParentNode = parent;

            // Read attributes if they exist
            if (reader.HasAttributes)
            {
                reader.MoveToFirstAttribute();
                do
                {
                    WsXmlAttribute attribute = new WsXmlAttribute();
                    attribute.Value = reader.Value;
                    attribute.LocalName = reader.LocalName;
                    if (reader.NamespaceURI != String.Empty)
                    {
                        attribute.NamespaceURI = reader.NamespaceURI;
                    }

                    attribute.Prefix = reader.Prefix;
                    node.Attributes.Append(attribute);
                }

                while (reader.MoveToNextAttribute());

                reader.MoveToElement();
            }
        }
Beispiel #24
0
		internal static XElement LoadCore (XmlReader r, LoadOptions options)
		{
			r.MoveToContent ();
			if (r.NodeType != XmlNodeType.Element)
				throw new InvalidOperationException ("The XmlReader must be positioned at an element");
			XName name = XName.Get (r.LocalName, r.NamespaceURI);
			XElement e = new XElement (name);
			e.FillLineInfoAndBaseUri (r, options);

			if (r.MoveToFirstAttribute ()) {
				do {
					// not sure how current Orcas behavior makes sense here though ...
					if (r.LocalName == "xmlns" && r.NamespaceURI == XNamespace.Xmlns.NamespaceName)
						e.SetAttributeValue (XNamespace.None.GetName ("xmlns"), r.Value);
					else
						e.SetAttributeValue (XName.Get (r.LocalName, r.NamespaceURI), r.Value);
					e.LastAttribute.FillLineInfoAndBaseUri (r, options);
				} while (r.MoveToNextAttribute ());
				r.MoveToElement ();
			}
			if (!r.IsEmptyElement) {
				r.Read ();
				e.ReadContentFrom (r, options);
				r.ReadEndElement ();
				e.explicit_is_empty = false;
			} else {
				e.explicit_is_empty = true;
				r.Read ();
			}
			return e;
		}
Beispiel #25
0
        /* -------------------------------------------------------------------------------------
        * Name:  WriteShallowNode
        * Goal:  Copy piece-by-piece
        * History:
        * 2/oct/2015 ERK Created
          ------------------------------------------------------------------------------------- */
        public void WriteShallowNode(XmlReader reader, XmlWriter writer)
        {
            if (reader == null) {
            throw new ArgumentNullException("reader");
              }
              if (writer == null) {
            throw new ArgumentNullException("writer");
              }
              try {
            switch (reader.NodeType) {
              case XmlNodeType.Element:
            writer.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI);
            bool bIsFOLIA = (reader.LocalName == "FoLiA");
            string sLocalName = reader.LocalName;
            // Process attributes one by one
            if (reader.HasAttributes) {
              if (reader.MoveToFirstAttribute()) {
                do {
                  if (reader.Name != "xmlns") {
                    bool bWritten = false;
                    // Action depends on local name
                    switch (sLocalName) {
                      case "FoLiA":
                        // Is the the attribute @version?
                        if (reader.Name == "version") { writer.WriteAttributeString(reader.Name, FOLIA_VERSION); bWritten = true; }
                        break;
                      case "t":
                        // is this the attribute @class?
                        if (reader.Name == "class") { writer.WriteAttributeString(reader.Name, "eng"); bWritten = true; }
                        break;
                    }
                    if (!bWritten) {
                      String[] arName = reader.Name.Split(':');
                      if (arName.Length > 1) {
                        writer.WriteAttributeString(arName[0], arName[1], null, reader.Value);

                      } else {
                        writer.WriteAttributeString(reader.Name, reader.Value);
                      }
                    }
                    /*
                    // Check for FoLiA version
                    if (bIsFOLIA && reader.Name == "version") {
                      // Adapt version number
                      writer.WriteAttributeString(reader.Name, FOLIA_VERSION);
                    } else {
                      String[] arName = reader.Name.Split(':');
                      if (arName.Length > 1) {
                        writer.WriteAttributeString(arName[0], arName[1], null, reader.Value);

                      } else {
                        writer.WriteAttributeString(reader.Name, reader.Value);
                      }
                    } */
                  }
                } while (reader.MoveToNextAttribute());
              }
            }

            if (reader.IsEmptyElement) {
              writer.WriteEndElement();
            }
            break;
              case XmlNodeType.Text:
            writer.WriteString(reader.Value);
            break;
              case XmlNodeType.Whitespace:
              case XmlNodeType.SignificantWhitespace:
            writer.WriteWhitespace(reader.Value);
            break;
              case XmlNodeType.CDATA:
            writer.WriteCData(reader.Value);
            break;
              case XmlNodeType.EntityReference:
            writer.WriteEntityRef(reader.Name);
            break;
              case XmlNodeType.XmlDeclaration:
              case XmlNodeType.ProcessingInstruction:
            writer.WriteProcessingInstruction(reader.Name, reader.Value);
            break;
              case XmlNodeType.DocumentType:
            writer.WriteDocType(reader.Name, reader.GetAttribute("PUBLIC"), reader.GetAttribute("SYSTEM"), reader.Value);
            break;
              case XmlNodeType.Comment:
            writer.WriteComment(reader.Value);
            break;
              case XmlNodeType.EndElement:
            writer.WriteFullEndElement();
            break;
            }
              } catch (Exception ex) {
            errHandle.DoError("WriteShallowNode", ex); // Provide standard error message
              }
        }
Beispiel #26
0
        /// <summary>
        /// Converts XML to JsonML array form.
        /// </summary>

        public static void EncodeArrayForm(XmlReader reader, JsonWriter writer)
        {
            if (reader == null) throw new ArgumentNullException("reader");
            if (writer == null) throw new ArgumentNullException("writer");

            if (reader.MoveToContent() != XmlNodeType.Element)
                throw new ArgumentException(null, "reader");

            writer.WriteStartArray();
            writer.WriteString(reader.Name);

            //
            // Write attributes
            //

            if (reader.MoveToFirstAttribute())
            {
                writer.WriteStartObject();

                do
                {
                    writer.WriteMember(reader.Name);
                    writer.WriteString(reader.Value);
                }
                while (reader.MoveToNextAttribute());

                writer.WriteEndObject();
                reader.MoveToElement();
            }

            bool isEmpty = reader.IsEmptyElement;

            if (!isEmpty)
            {
                reader.Read();

                //
                // Write child nodes (text, CDATA and element)
                //

                while (reader.NodeType != XmlNodeType.EndElement)
                {
                    if (reader.NodeType == XmlNodeType.Text || reader.NodeType == XmlNodeType.CDATA)
                    {
                        writer.WriteString(reader.Value);
                        reader.Read();
                    }
                    else if (reader.NodeType == XmlNodeType.Element)
                    {
                        Encode(reader, writer);
                    }
                    else
                    {
                        reader.Read();
                    }
                }
            }

            writer.WriteEndArray();
            reader.Read();
        }
Beispiel #27
0
        // XmlReader Helper Methods

        // Writes out all the attributes found at the current position in the specified XmlReader.
        public virtual void WriteAttributes(XmlReader reader, bool defattr)
        {
            if (null == reader)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            if (reader.NodeType == XmlNodeType.Element || reader.NodeType == XmlNodeType.XmlDeclaration)
            {
                if (reader.MoveToFirstAttribute())
                {
                    WriteAttributes(reader, defattr);
                    reader.MoveToElement();
                }
            }
            else if (reader.NodeType != XmlNodeType.Attribute)
            {
                throw new XmlException(SR.Xml_InvalidPosition, string.Empty);
            }
            else
            {
                do
                {
                    // we need to check both XmlReader.IsDefault and XmlReader.SchemaInfo.IsDefault. 
                    // If either of these is true and defattr=false, we should not write the attribute out
                    if (defattr || !reader.IsDefaultInternal)
                    {
                        WriteStartAttribute(reader.Prefix, reader.LocalName, reader.NamespaceURI);
                        while (reader.ReadAttributeValue())
                        {
                            if (reader.NodeType == XmlNodeType.EntityReference)
                            {
                                WriteEntityRef(reader.Name);
                            }
                            else
                            {
                                WriteString(reader.Value);
                            }
                        }
                        WriteEndAttribute();
                    }
                }
                while (reader.MoveToNextAttribute());
            }
        }
Beispiel #28
0
        private void ParseStep(XmlReader reader, Stack<ElementRecord> elementStack, ref TextRecord textChunk, PhpArray values, PhpArray indices)
        {
            string elementName;
            bool emptyElement;
            ElementRecord currentElementRecord = null;

            switch (reader.NodeType)
            {
                case XmlNodeType.Element:
                    elementName = reader.Name;
                    emptyElement = reader.IsEmptyElement;
                    PhpArray attributeArray = new PhpArray();

                    if (_processNamespaces && elementName.IndexOf(":") >= 0)
                    {
                        string localName = elementName.Substring(elementName.IndexOf(":") + 1);
                        elementName = reader.NamespaceURI + _namespaceSeparator + localName;
                    }

                    if (reader.MoveToFirstAttribute())
                    {
                        do
                        {                           
                            if (_processNamespaces && reader.Name.StartsWith("xmlns:"))
                            {
                                string namespaceID = reader.Name.Substring(6);
                                string namespaceUri = reader.Value;

                                if (_startNamespaceDeclHandler.Callback != null)
                                    _startNamespaceDeclHandler.Invoke(this, namespaceID, namespaceUri);

                                continue;
                            }

                            attributeArray.Add(_enableCaseFolding ? reader.Name.ToUpperInvariant() : reader.Name, reader.Value);
                        }
                        while (reader.MoveToNextAttribute());   
                    }

                    // update current top of stack
                    if (elementStack.Count != 0)
                    {
                        currentElementRecord = elementStack.Peek();

                        UpdateValueAndIndexArrays(currentElementRecord, ref textChunk, values, indices, true);

                        if (currentElementRecord.State == ElementState.Beginning)
                            currentElementRecord.State = ElementState.Interior;
                    }

                    // push the element into the stack (needed for parse_into_struct)
                    elementStack.Push(
                        new ElementRecord() { 
                            ElementName = elementName,
                            Level = reader.Depth, 
                            State = ElementState.Beginning, 
                            Attributes = (PhpArray)attributeArray.DeepCopy() 
                        });

                    if (_startElementHandler.Callback != null)
                        _startElementHandler.Invoke(this, _enableCaseFolding ? elementName.ToUpperInvariant() : elementName, attributeArray);
                    else
                        if (_defaultHandler.Callback != null) _defaultHandler.Invoke(this, "");

                    if (emptyElement) goto case XmlNodeType.EndElement;    // and end the element immediately (<element/>, XmlNodeType.EndElement will not be called)
                    
                    break;


                case XmlNodeType.EndElement:
                    elementName = reader.Name;

                    if (_processNamespaces && elementName.IndexOf(":") >= 0)
                    {
                        string localName = elementName.Substring(elementName.IndexOf(":") + 1);
                        elementName = reader.NamespaceURI + _namespaceSeparator + localName;
                    }

                    // pop the top element record
                    currentElementRecord = elementStack.Pop();

                    UpdateValueAndIndexArrays(currentElementRecord, ref textChunk, values, indices, false);

                    if (_endElementHandler.Callback != null)
                        _endElementHandler.Invoke(this, _enableCaseFolding ? elementName.ToUpperInvariant() : elementName);
                    else
                        if (_defaultHandler.Callback != null) _defaultHandler.Invoke(this, "");
                    break;


                case XmlNodeType.Whitespace:
                case XmlNodeType.Text:
                case XmlNodeType.CDATA:
                    if (textChunk == null)
                    {
                        textChunk = new TextRecord() { Text = reader.Value };
                    }
                    else
                    {
                        textChunk.Text += reader.Value;
                    }

                    if (_characterDataHandler.Callback != null)
                        _characterDataHandler.Invoke(this, reader.Value);
                    else
                        if (_defaultHandler.Callback != null) _defaultHandler.Invoke(this, reader.Value);
                    break;

                case XmlNodeType.ProcessingInstruction:

                    if (_processingInstructionHandler.Callback != null)
                        _processingInstructionHandler.Invoke(this, reader.Name, reader.Value);
                    else
                        if (_defaultHandler.Callback != null) _defaultHandler.Invoke(this, string.Empty);
                    break;
            }
        }
Beispiel #29
0
        private XmlNode LoadNode(bool skipOverWhitespace)
        {
            XmlElement     element;
            IXmlSchemaInfo schemaInfo;
            XmlNode        node2;
            XmlReader      reader     = this.reader;
            XmlNode        parentNode = null;

Label_0009:
            node2 = null;
            switch (reader.NodeType)
            {
            case XmlNodeType.Element:
            {
                bool isEmptyElement = reader.IsEmptyElement;
                element         = this.doc.CreateElement(reader.Prefix, reader.LocalName, reader.NamespaceURI);
                element.IsEmpty = isEmptyElement;
                if (reader.MoveToFirstAttribute())
                {
                    XmlAttributeCollection attributes = element.Attributes;
                    do
                    {
                        XmlAttribute attribute = this.LoadAttributeNode();
                        attributes.Append(attribute);
                    }while (reader.MoveToNextAttribute());
                    reader.MoveToElement();
                }
                if (isEmptyElement)
                {
                    schemaInfo = reader.SchemaInfo;
                    if (schemaInfo != null)
                    {
                        element.XmlName = this.doc.AddXmlName(element.Prefix, element.LocalName, element.NamespaceURI, schemaInfo);
                    }
                    node2 = element;
                    break;
                }
                if (parentNode != null)
                {
                    parentNode.AppendChildForLoad(element, this.doc);
                }
                parentNode = element;
                goto Label_025B;
            }

            case XmlNodeType.Attribute:
                node2 = this.LoadAttributeNode();
                break;

            case XmlNodeType.Text:
                node2 = this.doc.CreateTextNode(reader.Value);
                break;

            case XmlNodeType.CDATA:
                node2 = this.doc.CreateCDataSection(reader.Value);
                break;

            case XmlNodeType.EntityReference:
                node2 = this.LoadEntityReferenceNode(false);
                break;

            case XmlNodeType.ProcessingInstruction:
                node2 = this.doc.CreateProcessingInstruction(reader.Name, reader.Value);
                break;

            case XmlNodeType.Comment:
                node2 = this.doc.CreateComment(reader.Value);
                break;

            case XmlNodeType.DocumentType:
                node2 = this.LoadDocumentTypeNode();
                break;

            case XmlNodeType.Whitespace:
                if (!this.preserveWhitespace)
                {
                    if ((parentNode == null) && !skipOverWhitespace)
                    {
                        return(null);
                    }
                    goto Label_025B;
                }
                node2 = this.doc.CreateWhitespace(reader.Value);
                break;

            case XmlNodeType.SignificantWhitespace:
                node2 = this.doc.CreateSignificantWhitespace(reader.Value);
                break;

            case XmlNodeType.EndElement:
                if (parentNode != null)
                {
                    schemaInfo = reader.SchemaInfo;
                    if (schemaInfo != null)
                    {
                        element = parentNode as XmlElement;
                        if (element != null)
                        {
                            element.XmlName = this.doc.AddXmlName(element.Prefix, element.LocalName, element.NamespaceURI, schemaInfo);
                        }
                    }
                    if (parentNode.ParentNode == null)
                    {
                        return(parentNode);
                    }
                    parentNode = parentNode.ParentNode;
                    goto Label_025B;
                }
                return(null);

            case XmlNodeType.EndEntity:
                return(null);

            case XmlNodeType.XmlDeclaration:
                node2 = this.LoadDeclarationNode();
                break;

            default:
                throw UnexpectedNodeType(reader.NodeType);
            }
            if (parentNode != null)
            {
                parentNode.AppendChildForLoad(node2, this.doc);
            }
            else
            {
                return(node2);
            }
Label_025B:
            if (reader.Read())
            {
                goto Label_0009;
            }
            if (parentNode != null)
            {
                while (parentNode.ParentNode != null)
                {
                    parentNode = parentNode.ParentNode;
                }
            }
            return(parentNode);
        }
Beispiel #30
0
 public override bool MoveToFirstAttribute()
 {
     return(reader.MoveToFirstAttribute());
 }
 public override bool MoveToFirstAttribute()
 {
     CheckAsync();
     return(_coreReader.MoveToFirstAttribute());
 }
Beispiel #32
0
        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);
        }
    /// <summary>
    /// Writes the element attributes from the reader to the writer
    /// </summary>
    protected virtual void WriteAttributes(XmlReader reader, XmlWriter writer) {
      Contract.Requires(reader != null);
      Contract.Requires(writer != null);

      if (reader.MoveToFirstAttribute()) {
        do { writer.WriteAttributeString(reader.Name, reader.Value); }
        while (reader.MoveToNextAttribute());
      }
    }
Beispiel #34
0
		private void TestAttributeDefaultContributionInternal (XmlReader dvr)
		{
			dvr.Read ();	// DTD
			dvr.Read ();
			Assert.AreEqual (XmlNodeType.Element, dvr.NodeType);
			Assert.AreEqual ("root", dvr.Name);
			Assert.AreEqual (2, dvr.AttributeCount);
			// foo
			Assert.IsTrue (dvr.MoveToFirstAttribute ());
			Assert.AreEqual ("foo", dvr.Name);
			Assert.AreEqual ("foo-def", dvr ["foo"]);
			Assert.IsNotNull (dvr ["bar"]);
			Assert.AreEqual ("foo-def", dvr.Value);
			Assert.IsTrue (dvr.ReadAttributeValue ());
			Assert.AreEqual (XmlNodeType.Text, dvr.NodeType);
			Assert.AreEqual (String.Empty, dvr.Name);
			Assert.AreEqual ("foo-def", dvr.Value);
			// bar
			Assert.IsTrue (dvr.MoveToNextAttribute ());
			Assert.AreEqual ("bar", dvr.Name);
			Assert.AreEqual ("foo-def", dvr ["foo"]);
			Assert.IsNotNull (dvr ["bar"]);
			Assert.AreEqual ("bar-def", dvr.Value);
			Assert.IsTrue (dvr.ReadAttributeValue ());
			Assert.AreEqual (XmlNodeType.Text, dvr.NodeType);
			Assert.AreEqual (String.Empty, dvr.Name);
			Assert.AreEqual ("bar-def", dvr.Value);
		}
Beispiel #35
0
        // 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 = null;
                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);
        }
 /// -----------------------------------------------------------------------------
 /// <summary>
 /// Reads a Supported Features from an XmlReader
 /// </summary>
 /// <param name="reader">The XmlReader to use</param>
 /// <history>
 /// 	[cnurse]	01/17/2008   Created
 /// </history>
 /// -----------------------------------------------------------------------------
 private void ReadSupportedFeatures(XmlReader reader)
 {
     SupportedFeatures = 0;
     reader.ReadStartElement("supportedFeatures");
     do
     {
         if (reader.HasAttributes)
         {
             reader.MoveToFirstAttribute();
             switch (reader.ReadContentAsString())
             {
                 case "Portable":
                     IsPortable = true;
                     break;
                 case "Searchable":
                     IsSearchable = true;
                     break;
                 case "Upgradeable":
                     IsUpgradeable = true;
                     break;
             }
         }
     } while (reader.ReadToNextSibling("supportedFeature"));
 }
        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);
        }
        private static bool CompareAttributes(
            XmlReader reader1,
            XmlReader reader2)
        {
            bool more = true;

            more = reader1.MoveToFirstAttribute();
            if (more ^ reader2.MoveToFirstAttribute())
            {
                return false;
            }

            while (more)
            {
                if (reader1.Prefix == "xmlns")
                {
                    if (reader2.Prefix != "xmlns" ||
                        reader1.IsEmptyElement != reader2.IsEmptyElement ||
                        reader1.Value != reader2.Value)
                    {
                        return false;
                    }
                }
                else
                {
                    if (reader1.LocalName != reader2.LocalName ||
                        reader1.NamespaceURI != reader2.NamespaceURI ||
                        reader1.IsEmptyElement != reader2.IsEmptyElement ||
                        reader1.Value != reader2.Value)
                    {
                        return false;
                    }
                }

                more = reader1.MoveToNextAttribute();
                if (more ^ reader2.MoveToNextAttribute())
                {
                    return false;
                }
            }

            return true;
        }
Beispiel #39
0
        private XmlNode LoadNode(bool skipOverWhitespace)
        {
            XmlReader      r      = _reader;
            XmlNode        parent = null;
            XmlElement     element;
            IXmlSchemaInfo schemaInfo;

            do
            {
                XmlNode node = null;
                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)
                    {
                        if (parent != null)
                        {
                            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);
        }
Beispiel #40
0
        /// <summary>
        /// Converts XML to JsonML object form.
        /// </summary>

        public static void EncodeObjectForm(XmlReader reader, JsonWriter writer)
        {
            if (reader == null) throw new ArgumentNullException("reader");
            if (writer == null) throw new ArgumentNullException("writer");

            if (reader.MoveToContent() != XmlNodeType.Element)
                throw new ArgumentException(null, "reader");

            writer.WriteStartObject();
            writer.WriteMember("tagName");
            writer.WriteString(reader.Name);

            //
            // Write attributes
            //

            if (reader.MoveToFirstAttribute())
            {
                do
                {
                    writer.WriteMember(reader.Name);
                    writer.WriteString(reader.Value);
                }
                while (reader.MoveToNextAttribute());

                reader.MoveToElement();
            }

            bool isEmpty = reader.IsEmptyElement;

            if (!isEmpty)
            {
                reader.Read();

                int childCount = 0;

                //
                // Write child nodes (text, CDATA and element)
                //

                XmlNodeType nodeType;
                while ((nodeType = reader.NodeType) != XmlNodeType.EndElement)
                {
                    if (nodeType == XmlNodeType.Text 
                        || nodeType == XmlNodeType.CDATA 
                        || nodeType == XmlNodeType.Element)
                    {
                        if (childCount == 0)
                        {
                            writer.WriteMember("childNodes");
                            writer.WriteStartArray();
                        }

                        if (nodeType == XmlNodeType.Text || nodeType == XmlNodeType.CDATA)
                        {
                            writer.WriteString(reader.Value);
                            reader.Read();
                        }
                        else if (nodeType == XmlNodeType.Element)
                        {
                            EncodeObjectForm(reader, writer);
                        }

                        childCount++;
                    }
                    else
                    {
                        reader.Read();
                    }
                }

                if (childCount > 0)
                    writer.WriteEndArray();
            }

            writer.WriteEndObject();
            reader.Read();
        }
Beispiel #41
0
        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);
        }