Beispiel #1
0
        /// <summary> Encodes a Composite in XML by looping through it's components, creating new
        /// children for each of them (with the appropriate names) and populating them by
        /// calling encode(Type, Element) using these children.  Returns true if at least
        /// one component contains a value.
        /// </summary>
        private bool encodeComposite(Composite datatypeObject, System.Xml.XmlElement datatypeElement)
        {
            Type[] components = datatypeObject.Components;
            bool   hasValue   = false;

            for (int i = 0; i < components.Length; i++)
            {
                System.String         name    = makeElementName(datatypeObject, i + 1);
                System.Xml.XmlElement newNode = datatypeElement.OwnerDocument.CreateElement(name);
                bool componentHasValue        = encode(components[i], newNode);
                if (componentHasValue)
                {
                    try
                    {
                        datatypeElement.AppendChild(newNode);
                    }
                    catch (System.Exception e)
                    {
                        throw new DataTypeException("DOMException encoding Composite: ", e);
                    }
                    hasValue = true;
                }
            }
            return(hasValue);
        }
Beispiel #2
0
 /// <summary> Populates a Composite type by looping through it's children, finding corresponding
 /// Elements among the children of the given Element, and calling parse(Type, Element) for
 /// each.
 /// </summary>
 private void  parseComposite(Composite datatypeObject, System.Xml.XmlElement datatypeElement)
 {
     if (datatypeObject is GenericComposite)
     {
         //elements won't be named GenericComposite.x
         System.Xml.XmlNodeList children = datatypeElement.ChildNodes;
         int compNum = 0;
         for (int i = 0; i < children.Count; i++)
         {
             if (System.Convert.ToInt16(children.Item(i).NodeType) == (short)System.Xml.XmlNodeType.Element)
             {
                 parse(datatypeObject.getComponent(compNum), (System.Xml.XmlElement)children.Item(i));
                 compNum++;
             }
         }
     }
     else
     {
         Type[] children = datatypeObject.Components;
         for (int i = 0; i < children.Length; i++)
         {
             System.Xml.XmlNodeList matchingElements = datatypeElement.GetElementsByTagName(makeElementName(datatypeObject, i + 1));
             if (matchingElements.Count > 0)
             {
                 parse(children[i], (System.Xml.XmlElement)matchingElements.Item(0));                          //components don't repeat - use 1st
             }
         }
     }
 }
Beispiel #3
0
 /// <summary>Returns the expected XML element name for the given child of the given Composite </summary>
 private System.String makeElementName(Composite composite, int child)
 {
     return(composite.Name + "." + child);
 }
		/// <summary> Encodes a Composite in XML by looping through it's components, creating new 
		/// children for each of them (with the appropriate names) and populating them by 
		/// calling encode(Type, Element) using these children.  Returns true if at least 
		/// one component contains a value.  
		/// </summary>
		private bool encodeComposite(Composite datatypeObject, System.Xml.XmlElement datatypeElement)
		{
			Type[] components = datatypeObject.Components;
			bool hasValue = false;
			for (int i = 0; i < components.Length; i++)
			{
				System.String name = makeElementName(datatypeObject, i + 1);
				System.Xml.XmlElement newNode = datatypeElement.OwnerDocument.CreateElement(name);
				bool componentHasValue = encode(components[i], newNode);
				if (componentHasValue)
				{
					try
					{
						datatypeElement.AppendChild(newNode);
					}
					catch (System.Exception e)
					{
						throw new DataTypeException("DOMException encoding Composite: ", e);
					}
					hasValue = true;
				}
			}
			return hasValue;
		}
		/// <summary>Returns the expected XML element name for the given child of the given Composite </summary>
		private System.String makeElementName(Composite composite, int child)
		{
			return composite.Name + "." + child;
		}
		/// <summary> Populates a Composite type by looping through it's children, finding corresponding 
		/// Elements among the children of the given Element, and calling parse(Type, Element) for
		/// each.
		/// </summary>
		private void  parseComposite(Composite datatypeObject, System.Xml.XmlElement datatypeElement)
		{
			if (datatypeObject is GenericComposite)
			{
				//elements won't be named GenericComposite.x
				System.Xml.XmlNodeList children = datatypeElement.ChildNodes;
				int compNum = 0;
				for (int i = 0; i < children.Count; i++)
				{
					if (System.Convert.ToInt16(children.Item(i).NodeType) == (short) System.Xml.XmlNodeType.Element)
					{
						parse(datatypeObject.getComponent(compNum), (System.Xml.XmlElement) children.Item(i));
						compNum++;
					}
				}
			}
			else
			{
				Type[] children = datatypeObject.Components;
				for (int i = 0; i < children.Length; i++)
				{
					System.Xml.XmlNodeList matchingElements = datatypeElement.GetElementsByTagName(makeElementName(datatypeObject, i + 1));
					if (matchingElements.Count > 0)
					{
						parse(children[i], (System.Xml.XmlElement) matchingElements.Item(0)); //components don't repeat - use 1st
					}
				}
			}
		}