Rhino.Xmlimpl.XMLName.SetMyValueOn C# (CSharp) Method

SetMyValueOn() private method

private SetMyValueOn ( XML target, object value ) : void
target XML
value object
return void
		internal virtual void SetMyValueOn(XML target, object value)
		{
			// Special-case checks for undefined and null
			if (value == null)
			{
				value = "null";
			}
			else
			{
				if (value is Undefined)
				{
					value = "undefined";
				}
			}
			Rhino.Xmlimpl.XMLName xmlName = this;
			// Get the named property
			if (xmlName.IsAttributeName())
			{
				target.SetAttribute(xmlName, value);
			}
			else
			{
				if (xmlName.Uri() == null && xmlName.LocalName().Equals("*"))
				{
					target.SetChildren(value);
				}
				else
				{
					// Convert text into XML if needed.
					XMLObjectImpl xmlValue = null;
					if (value is XMLObjectImpl)
					{
						xmlValue = (XMLObjectImpl)value;
						// Check for attribute type and convert to textNode
						if (xmlValue is XML)
						{
							if (((XML)xmlValue).IsAttribute())
							{
								xmlValue = target.MakeXmlFromString(xmlName, xmlValue.ToString());
							}
						}
						if (xmlValue is XMLList)
						{
							for (int i = 0; i < xmlValue.Length(); i++)
							{
								XML xml = ((XMLList)xmlValue).Item(i);
								if (xml.IsAttribute())
								{
									((XMLList)xmlValue).Replace(i, target.MakeXmlFromString(xmlName, xml.ToString()));
								}
							}
						}
					}
					else
					{
						xmlValue = target.MakeXmlFromString(xmlName, ScriptRuntime.ToString(value));
					}
					XMLList matches = target.GetPropertyList(xmlName);
					if (matches.Length() == 0)
					{
						target.AppendChild(xmlValue);
					}
					else
					{
						// Remove all other matches
						for (int i = 1; i < matches.Length(); i++)
						{
							target.RemoveChild(matches.Item(i).ChildIndex());
						}
						// Replace first match with new value.
						XML firstMatch = matches.Item(0);
						target.Replace(firstMatch.ChildIndex(), xmlValue);
					}
				}
			}
		}

Usage Example

Example #1
0
		internal override void PutXMLProperty(XMLName xmlName, object value)
		{
			if (IsPrototype())
			{
			}
			else
			{
				//    TODO    Is this really a no-op?  Check the spec to be sure
				xmlName.SetMyValueOn(this, value);
			}
		}