Getting an error in my xml schema editor code.

Hi,
I have an xsd file like this.
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="generic" 
elementFormDefault="qualified" targetNamespace="generic"> 
   <xsd:element name="bookstore" type="bookstoreType"/> 
   <xsd:complexType name="bookstoreType"> 
       <xsd:sequence maxOccurs="unbounded"> 
           <xsd:element name="book" type="bookType"/> 
       </xsd:sequence> 
   </xsd:complexType> 
   <xsd:complexType name="bookType"> 
       <xsd:sequence> 
           <xsd:element name="title" type="xsd:string"/> 
           <xsd:element name="author" type="authorName"/> 
           <xsd:element name="price" type="xsd:decimal"/> 
       </xsd:sequence> 
       <xsd:attribute name="genre" type="xsd:string"/> 
   </xsd:complexType> 
   <xsd:complexType name="authorName"> 
       <xsd:sequence> 
           <xsd:element name="first-name" type="xsd:string"/> 
           <xsd:element name="last-name" type="xsd:string"/> 
       </xsd:sequence> 
   </xsd:complexType> 
</xsd:schema> 

And my xml schema editor code is as follows
	private void mnuAddAnnotation_Click(object sender, System.EventArgs e)
		{
			XmlSchemaAnnotation annot=new XmlSchemaAnnotation();
			TreeNode newNode=CreateNode("--annotation--");

			// if adding at the schema root level...
			if (newNode.Parent==tvSchema.Nodes[0])
			{
				AddToCollection(schema.Items, annot, newNode, TreeViewImages.Annotation);
			}
			else
			{
				// otherwise, get the object as an XmlSchemaAnnotated type
				XmlSchemaAnnotated obj=newNode.Parent.Tag as XmlSchemaAnnotated;
				if (obj != null)
				{
					// if it exists, add the annotation
					obj.Annotation=annot;
					newNode.Tag=annot;
					newNode.ImageIndex=(int)TreeViewImages.Annotation;
					newNode.SelectedImageIndex=(int)TreeViewImages.Annotation;
					CompileSchema();
				}
				else
				{
					// otherwise, tell the user annotation cannot be added to this type.
					newNode.Parent.Nodes.Remove(newNode);
					MessageBox.Show("Cannot create an annotation for this item.");
				}
			}
		}

		private void mnuAddDocumentation_Click(object sender, System.EventArgs e)
		{
			bool success=false;
			XmlSchemaAnnotation annot=tvSchema.SelectedNode.Tag as XmlSchemaAnnotation;
			// if the parent node is an annotation type...
			if (annot != null)
			{
				// ...then add the documentation type
				TreeNode newNode=CreateNode("--documentation--");
				XmlSchemaDocumentation doc=new XmlSchemaDocumentation();
				doc.Markup=TextToNodeArray("Documentation");
				annot.Items.Add(doc);
				newNode.Tag=doc;
				newNode.ImageIndex=(int)TreeViewImages.Annotation;
				newNode.SelectedImageIndex=(int)TreeViewImages.Annotation;
				CompileSchema();
				success=true;
			}
			if (!success)
			{
				// otherwise create the annotation type first
				mnuAddAnnotation_Click(sender, e);
				annot=tvSchema.SelectedNode.Tag as XmlSchemaAnnotation;
				// if successful in adding the annotation type, add the documentation 
type now
				if (annot != null)
				{
					mnuAddDocumentation_Click(sender, e);
				}
			}
		}

		private void mnuAddAppInfo_Click(object sender, System.EventArgs e)
		{
			bool success=false;
			XmlSchemaAnnotation annot=tvSchema.SelectedNode.Tag as XmlSchemaAnnotation;
			// if the parent node is an annotation type...
			if (annot != null)
			{
				// ...then add the AppInfo type
				TreeNode newNode=CreateNode("--app info--");
				XmlSchemaAppInfo doc=new XmlSchemaAppInfo();
				doc.Markup=TextToNodeArray("Application Information");
				annot.Items.Add(doc);
				newNode.Tag=doc;
				newNode.ImageIndex=(int)TreeViewImages.Annotation;
				newNode.SelectedImageIndex=(int)TreeViewImages.Annotation;
				CompileSchema();
				success=true;
			}
			if (!success)
			{
				// otherwise create the annotation type first
				mnuAddAnnotation_Click(sender, e);
				annot=tvSchema.SelectedNode.Tag as XmlSchemaAnnotation;
				// if successful in creating the annotation type, add the AppInfo type now
				if (annot != null)
				{
					mnuAddAppInfo_Click(sender, e);
				}
			}
		}

		private void mnuAddAttribute_Click(object sender, System.EventArgs e)
		{
			TreeNode newNode=CreateNode("Attribute");
			XmlSchemaAttribute attrib=new XmlSchemaAttribute();
			attrib.Name="Attribute";
			attrib.SchemaTypeName=new XmlQualifiedName("string", 
"http://www.w3.org/2001/XMLSchema");

			// root node?
			if (newNode.Parent==tvSchema.Nodes[0])
			{
				// add to root of schema.  An global attribute cannot reference a global 
type
				AddToCollection(schema.Items, attrib, newNode, TreeViewImages.Attribute);
				cbGlobalTypes.Items.Add(new GlobalElementType(attrib.Name, attrib));
				cbGlobalTypes.Enabled=false;
				cbSimpleTypes.SelectedItem=-1;
				cbSimpleTypes.Enabled=true;
				cbSimpleTypes.SelectedItem="string";
			}
			else
			{
				// an attribute can only be added to a complex type
				XmlSchemaComplexType ct=newNode.Parent.Tag as XmlSchemaComplexType;
				if (ct != null)
				{
					// and can reference a global attribute, so enable the global combobox
					AddToCollection(ct.Attributes, attrib, newNode, 
TreeViewImages.Attribute);
					cbGlobalTypes.SelectedItem=-1;
					cbGlobalTypes.Enabled=true;
					cbSimpleTypes.SelectedItem="string";
					cbSimpleTypes.Enabled=true;
				}
				else
				{
					newNode.Parent.Nodes.Remove(newNode);
					MessageBox.Show("Cannot create an attribute for this item.");
				}
			}
		}
		private void mnuAddElement_Click(object sender, System.EventArgs e)
		{
			TreeNode newNode=CreateNode("Element");
			XmlSchemaElement element=new XmlSchemaElement();
			element.Name="Element";
			element.SchemaTypeName=new XmlQualifiedName("string", 
"http://www.w3.org/2001/XMLSchema");

			// root node?
			if (newNode.Parent==tvSchema.Nodes[0])
			{
				// add to root of schema.  A global element can reference another global 
type
				AddToCollection(schema.Items, element, newNode, TreeViewImages.Element);
				cbGlobalTypes.Items.Add(new GlobalElementType(element.Name, element));
				cbGlobalTypes.Enabled=true;
				cbSimpleTypes.SelectedItem=-1;
				cbSimpleTypes.Enabled=true;
				cbSimpleTypes.SelectedItem="string";
			}
			else
			{
				// otherwise, an element must be part of a complex type
				bool ret=AddToComplexType(newNode.Parent.Tag, element, newNode, 
TreeViewImages.Element);
				if (!ret)
				{
					// not successful
					newNode.Parent.Nodes.Remove(newNode);
					MessageBox.Show("Cannot add an element to this item.");
				}
				else
				{
					// successful
					cbGlobalTypes.SelectedItem=-1;
					cbGlobalTypes.Enabled=true;
					cbSimpleTypes.SelectedItem="string";
					cbSimpleTypes.Enabled=true;
				}
			}
		}
		
		private void mnuAddSimpleType_Click(object sender, System.EventArgs e)
		{
			TreeNode newNode=CreateNode("SimpleType");

			XmlSchemaSimpleType simpleType=new XmlSchemaSimpleType();
			simpleType.Name="SimpleType";
			XmlSchemaSimpleTypeRestriction restriction=new 
XmlSchemaSimpleTypeRestriction();
			restriction.BaseTypeName=new XmlQualifiedName("string", 
"http://www.w3.org/2001/XMLSchema");
			simpleType.Content=restriction;

			// root node?
			if (newNode.Parent==tvSchema.Nodes[0])
			{
				// add to root of schema.  A global simple type cannot reference another 
global
				AddToCollection(schema.Items, simpleType, newNode, 
TreeViewImages.SimpleType);
				cbGlobalTypes.Items.Add(new GlobalElementType(simpleType.Name, 
simpleType));
				cbGlobalTypes.Enabled=false;
				cbSimpleTypes.SelectedItem=-1;
				cbSimpleTypes.Enabled=true;
				cbSimpleTypes.SelectedItem="string";
			}
			else
			{
				// if not a root node, then it must be created as an element of simple 
type...
				XmlSchemaElement el=new XmlSchemaElement();
				el.Name="SimpleType";
				el.SchemaType=simpleType;
				simpleType.Name=null;
				// ...as a subnode to a complex type
				bool ret=AddToComplexType(newNode.Parent.Tag, el, newNode, 
TreeViewImages.SimpleType);
				if (!ret)
				{
					// failure
					newNode.Parent.Nodes.Remove(newNode);
					MessageBox.Show("Cannot add a simple type to this item.");
				}
				else
				{
					// success.  Can reference a global simple type
					cbGlobalTypes.SelectedItem=-1;
					cbGlobalTypes.Enabled=true;
					cbSimpleTypes.SelectedItem="string";
					cbSimpleTypes.Enabled=true;
				}
			}
		}
		
		private void mnuAddComplexType_Click(object sender, System.EventArgs e)
		{
			TreeNode newNode=CreateNode("ComplexType");

			XmlSchemaComplexType complexType=new XmlSchemaComplexType();
			XmlSchemaSequence sequence=new XmlSchemaSequence();
			complexType.Particle=sequence;
			complexType.Name="ComplexType";

			// root node?
			if (newNode.Parent==tvSchema.Nodes[0])
			{
				// add to root.  A complex type has no type reference information.
				AddToCollection(schema.Items, complexType, newNode, 
TreeViewImages.ComplexType);
				cbGlobalTypes.Items.Add(new GlobalElementType(complexType.Name, 
complexType));
				cbSimpleTypes.SelectedItem=-1;
				cbGlobalTypes.SelectedItem=-1;
				cbSimpleTypes.Enabled=false;
				cbGlobalTypes.Enabled=false;
			}
			else
			{
				// if not at root, create an element of complex type...
				XmlSchemaElement el=new XmlSchemaElement();
				el.Name="ComplexType";
				el.SchemaType=complexType;
				complexType.Name=null;
				// ...that is added as a subnode to a complex type.
				bool ret=AddToComplexType(newNode.Parent.Tag, el, newNode, 
TreeViewImages.ComplexType);
				if (!ret)
				{
					// failure
					newNode.Parent.Nodes.Remove(newNode);
					MessageBox.Show("Cannot add a complex type to this item.");
				}
				else
				{
					// success.  No type is referenced.
					cbSimpleTypes.SelectedItem=-1;
					cbGlobalTypes.SelectedItem=-1;
					cbSimpleTypes.Enabled=false;
					cbGlobalTypes.Enabled=false;
				}
			}
		}
				
		
		}
		
		private void SchemaValidationHandler(object sender, ValidationEventArgs 
args) 
		{
			Console.WriteLine(args.Message);
			edSchemaErrors.Text+=args.Message+"\r\n";
		}
		
		private void PreEventLabelChanged(object sender, NodeLabelEditEventArgs e)
		{
			prevLabel=tvSchema.SelectedNode.Text;
			if ( (e.Node.Tag is XmlSchemaFacet) ||
				(e.Node.Tag is XmlSchemaAnnotation) || 
				(e.Node.Tag is XmlSchemaDocumentation) ||
				(e.Node.Tag is XmlSchemaAppInfo) )
			{
				e.Node.EndEdit(false);
			}
		}

		private void EventLabelChanged(object sender, NodeLabelEditEventArgs e)
		{
			// if a node is selected...
			if (e.Node != null)
			{
				// and a label has been changed... (e.Label==null if ESC key pressed)
				if (e.Label != null)
				{
					// then change the name of the type in the schema
					UpdateTypeAndName(null, e.Label, null);

					// if this is a root node...
					if (e.Node.Parent == tvSchema.Nodes[0])
					{
						// ...then also change the name in the global list
						// (this is not case sensitive!)
						int idx=cbGlobalTypes.FindStringExact(prevLabel);
						if (idx != -1)
						{
							cbGlobalTypes.Items[idx]=new GlobalElementType(e.Label, 
((GlobalElementType)cbGlobalTypes.Items[idx]).type);
						}
					}
				}
			}
		}

		private void EventTreeViewKeyUp(object sender, KeyEventArgs e)
		{
			e.Handled=false;
			// F2
			if (e.KeyCode==Keys.F2)
			{
				if (tvSchema.SelectedNode != tvSchema.Nodes[0])
				{
					tvSchema.SelectedNode.BeginEdit();
					e.Handled=true;
				}
			}
			// Ctrl+A
			else if ( (e.KeyCode==Keys.A) && (e.Modifiers==Keys.Control) )
			{
				e.Handled=true;
				tvcmSchema.Show(this, tvSchema.Location+new Size(50, 50));
			}
			// Ctrl+T
			else if ( (e.KeyCode==Keys.T) && (e.Modifiers==Keys.Control) )
			{
				e.Handled=true;
				tvSchema.SelectedNode=tvSchema.Nodes[0];
			}
			// Ctrl+P
			else if ( (e.KeyCode==Keys.P) && (e.Modifiers==Keys.Control) )
			{
				e.Handled=true;
                
                TreeNode node = tvSchema.SelectedNode.Parent;
				if (node != null)
				{
					tvSchema.SelectedNode=node;
				}
			}
		}
		
		private void EventSchemaTextBoxLostFocus(object sender, EventArgs e)
		{
			mnuCompile_Click(sender, e);
		}
		
		private void EventMouseDown(object sender, MouseEventArgs e)
		{
			TreeNode tn=tvSchema.GetNodeAt(e.X, e.Y);
			if (tn != null)
			{
				tvSchema.SelectedNode=tn;
			}
		}
		
		private void tvSchema_AfterSelect(object sender, 
System.Windows.Forms.TreeViewEventArgs e)
		{
			XmlSchemaObject obj=e.Node.Tag as XmlSchemaObject;
			// if this is a schema object...
			if (obj != null)
			{
				// find the corresponding line in the XSD source and highlight it
				if ( (obj.LineNumber != 0) && (obj.LineNumber < edSchema.Lines.Length) )
				{
					int length=0;
					for (int i=0; i<obj.LineNumber-1; i++)
					{
						// get the length of the line including CRLF
						length+=edSchema.Lines[i].Length+2;
					}
					// highlight the line
					edSchema.Select(length, edSchema.Lines[obj.LineNumber-1].Length);
				}

				// Update simple and global type combo boxes.
				// Get the name of the element type so that we can find it in the simple 
or global type list
				XmlQualifiedName name=null;		// assume failure
				if (obj is XmlSchemaAttribute)
				{
					// this is easy.
					name=((XmlSchemaAttribute)obj).SchemaTypeName;
				}
				else if (obj is XmlSchemaSimpleType)
				{
					// if it's a simple type, get the restriction type, if it exists
					XmlSchemaSimpleTypeRestriction 
restriction=((XmlSchemaSimpleType)obj).Content as 
XmlSchemaSimpleTypeRestriction;
					if (restriction != null)
					{
						name=restriction.BaseTypeName;
					}
				}
				else if (obj is XmlSchemaElement)
				{
					// if it's an element, determine if it's a simple type subnode of a 
complex type...
					// and then get the restriction type, if it exists
					XmlSchemaElement el=obj as XmlSchemaElement;
					if (el.SchemaType is XmlSchemaSimpleType)
					{
						XmlSchemaSimpleType st=el.SchemaType as XmlSchemaSimpleType;
						XmlSchemaSimpleTypeRestriction rest=st.Content as 
XmlSchemaSimpleTypeRestriction;
						if (rest != null)
						{
							name=rest.BaseTypeName;
						}
					}
					else
					{
						// otherwise get the element name
						name=el.SchemaTypeName;

						// if the name is null, then there must be a reference instead
						if (name.Name=="")
						{
							name=el.RefName;
						}
					}
				}

				// select the name from either the simple type list or the global 
element type list
				if (name != null)
				{
					// see if the name exists in the simple type list
					int idx=cbSimpleTypes.FindStringExact(name.Name);
					cbSimpleTypes.SelectedIndex=idx;
					cbSimpleTypes.Enabled=true;

					// see if the name exists in the complex type list
					idx=cbGlobalTypes.FindStringExact(name.Name);
					cbGlobalTypes.SelectedIndex=idx;
					cbGlobalTypes.Enabled=true;
				}
				else
				{
					// if there is no name, then disable the comboboxes
					cbSimpleTypes.SelectedIndex=-1;
					cbGlobalTypes.SelectedIndex=-1;
					cbSimpleTypes.Enabled=false;
					cbGlobalTypes.Enabled=false;
				}
			}
			else
			{
				// if this isn't a schema object, then disable the comboboxes
				cbSimpleTypes.SelectedIndex=-1;
				cbGlobalTypes.SelectedIndex=-1;
				cbSimpleTypes.Enabled=false;
				cbGlobalTypes.Enabled=false;
			}
		}
		
		private void cbSimpleTypes_SelectedIndexChanged(object sender, 
System.EventArgs e)
		{
			if (cbSimpleTypes.SelectedIndex != -1)
			{
				UpdateTypeAndName(cbSimpleTypes.SelectedItem.ToString(), null, 
"http://www.w3.org/2001/XMLSchema");
				cbGlobalTypes.SelectedIndex=-1;
			}
		}
		
		private void cbGlobalTypes_SelectedIndexChanged(object sender, 
System.EventArgs e)
		{
			if (cbGlobalTypes.SelectedIndex != -1)
			{
				UpdateTypeAndName(cbGlobalTypes.SelectedItem.ToString(), null, null);
				cbSimpleTypes.SelectedIndex=-1;
			}
		}
		
		private void CreateRootNode()
		{
			tvSchema.Nodes.Clear();
			TreeNode rootNode=new TreeNode("Schema:");
			tvSchema.Nodes.Add(rootNode);
			rootNode.ImageIndex=(int)TreeViewImages.Schema;
			rootNode.SelectedImageIndex=(int)TreeViewImages.Schema;
			cbGlobalTypes.Items.Clear();
		}
	
		private void CompileSchema()
		{
			edSchemaErrors.Text="";
			schema.Compile(new ValidationEventHandler(SchemaValidationHandler));
			StringWriter sw=new StringWriter();
			schema.Write(sw);
			edSchema.Text=sw.ToString();

		}
		
		private TreeNode CreateNode(string name)
		{
			TreeNode tn=tvSchema.SelectedNode;
			TreeNode newNode=new TreeNode(name);
			tn.Nodes.Add(newNode);
			tn.Expand();
			tvSchema.SelectedNode=newNode;
			newNode.BeginEdit();
			return newNode;
		}
		
		void AddToCollection(XmlSchemaObjectCollection coll, XmlSchemaObject obj, 
TreeNode node, TreeViewImages imgIdx)
		{
			coll.Add(obj);
			node.Tag=obj;
			node.ImageIndex=(int)imgIdx;
			node.SelectedImageIndex=(int)imgIdx;
			CompileSchema();
		}
		
		private XmlSchemaComplexType ChangeElementToComplexType(XmlSchemaElement 
el, TreeNode tn)
		{
			// if the element is currently a reference, we need to remove the reference
			// and set the name to something, which in this case is the old ref name.
			if (el.RefName != null)
			{
				el.Name=el.RefName.Name;
				el.RefName=null;
			}
			// creat the complex type.
			XmlSchemaComplexType ct=new XmlSchemaComplexType();
			el.SchemaType=ct;
			// a complex type cannot have a type name
			el.SchemaTypeName=null;
			// create the sequence
			XmlSchemaSequence sequence=new XmlSchemaSequence();
			ct.Particle=sequence;

			// update the image indices
			tn.ImageIndex=(int)TreeViewImages.ComplexType;
			tn.SelectedImageIndex=(int)TreeViewImages.ComplexType;

			return ct;
		}
		
		private bool AddToComplexType(object obj, XmlSchemaObject item, TreeNode 
newNode, TreeViewImages imgIdx)
		{
			bool success=true;
			XmlSchemaElement el=obj as XmlSchemaElement;
			XmlSchemaComplexType complexType=obj as XmlSchemaComplexType;

			// is it an element...
			if (el != null)
			{
				// of complex type (so we know it's a local complex type, not a global 
one!)
				XmlSchemaComplexType ct=el.SchemaType as XmlSchemaComplexType;
				if (ct != null)
				{
					// does it have a sequence?
					XmlSchemaSequence seq=ct.Particle as XmlSchemaSequence;
					if (seq != null)
					{
						// yes--add it to the sequence collection
						AddToCollection(seq.Items, item, newNode, imgIdx);
					}
					else
					{
						// no--we can't add it.
						MessageBox.Show("Complex type is missing sequence!");
						success=false;
					}
				}
				else
				{
					// change the basic element to a complex type by adding a sequence and 
then
					// add the sub-element
					ct=ChangeElementToComplexType(el, newNode.Parent);
					AddToCollection(((XmlSchemaSequence)ct.Particle).Items, item, newNode, 
imgIdx);
				}
			}
			// or is it a global complex type...
			else	if (complexType != null)
			{
				XmlSchemaSequence seq=complexType.Particle as XmlSchemaSequence;
				// which should have a sequence!
				if (seq != null)
				{
					// yes--add it to the collection
					AddToCollection(seq.Items, item, newNode, imgIdx);
				}
				else
				{
					// no--we can't add it.
					MessageBox.Show("Complex type is missing sequence!");
					success=false;
				}
			}
			else
			{
				// failure--current node is not an element and not a complex type
				success=false;
			}
			return success;
		}
		
		private void UpdateTypeAndName(string typeName, string name, string 
nameSpace)
		{
			// Is the type referenced by the tree node an XmlSchemaObject?
            
            
            XmlSchemaObject obj = tvSchema.SelectedNode.Tag as 
XmlSchemaObject;
			if (obj != null)
			{
				// is it an attribute?
				if (obj is XmlSchemaAttribute)
				{
					XmlSchemaAttribute attrib=obj as XmlSchemaAttribute;
					// if we're changing the name:
					if (name != null)
					{
						attrib.Name=name;
						CompileSchema();
					}
					// if we're changing the type:
					if (typeName != null)
					{
						// if the name refers to a global attribute, then use ref instead of 
type
						int idx=cbGlobalTypes.FindStringExact(typeName);
						GlobalElementType glet=null;
						if (idx != -1)
						{
							glet=cbGlobalTypes.Items[idx] as GlobalElementType;
						}
						// if a global exists of this type...
						if ( (glet != null) && (glet.type is XmlSchemaAttribute) )
						{
							// then get rid of the type name and use a ref instead
							attrib.SchemaTypeName=null;
							attrib.RefName=new XmlQualifiedName(typeName, nameSpace);
							// can't have a name
							attrib.Name=null;
						}
						else
						{
							// otherwise, use a type name and get rid of the ref
							attrib.SchemaTypeName=new XmlQualifiedName(typeName, nameSpace);
							attrib.RefName=null;
							if (attrib.Name==null)
							{
								// if changing from ref to type, we need some sort of default name
								attrib.Name=tvSchema.SelectedNode.Text;
							}
						}
						CompileSchema();
						// update the tree node name
						tvSchema.SelectedNode.Text=attrib.QualifiedName.Name;
					}
				}
				// is it an element?
				else if (obj is XmlSchemaElement)
				{
					XmlSchemaElement el=obj as XmlSchemaElement;
					// if we're changing the name:
					if (name != null)
					{
						el.Name=name;
						CompileSchema();
					}

					// if we're changing the type:
					if (typeName != null)
					{
						if (el.SchemaType is XmlSchemaSimpleType)
						{
							XmlSchemaSimpleType st=el.SchemaType as XmlSchemaSimpleType;
							XmlSchemaSimpleTypeRestriction rest=st.Content as 
XmlSchemaSimpleTypeRestriction;
							if (rest != null)
							{
								rest.BaseTypeName=new XmlQualifiedName(typeName, nameSpace);
								CompileSchema();
							}
						}
						else
						{
							// if the name refers to a global element, then use ref instead of type
							// Same deal as for changing the element type name.
							// Since the SchemaTypeName and RefName are not part of any base 
class shared
							// between the SchemaXmlAttribute and SchemaXmlElement, we need 
separate code.
							int idx=cbGlobalTypes.FindStringExact(typeName);
							GlobalElementType glet=null;
							if (idx != -1)
							{
								glet=cbGlobalTypes.Items[idx] as GlobalElementType;
							}
							if ( (glet != null) && (glet.type is XmlSchemaElement) )
							{
								el.SchemaTypeName=null;
								el.RefName=new XmlQualifiedName(typeName, nameSpace);
								el.Name=null;
							}
							else
							{
								el.SchemaTypeName=new XmlQualifiedName(typeName, nameSpace);
								el.RefName=null;
								if (el.Name==null)
								{
									el.Name=tvSchema.SelectedNode.Text;
								}
							}
							CompileSchema();
							tvSchema.SelectedNode.Text=el.QualifiedName.Name;
						}
					}
				}
				// is it a simple type?
				else if (obj is XmlSchemaSimpleType)
				{
					XmlSchemaSimpleType st=obj as XmlSchemaSimpleType;
					// if we're changing the name:
					if (name != null)
					{
						st.Name=name;
						CompileSchema();
					}

					// if we're changing the type name:
					if (typeName != null)
					{
						// this must be done in the Restriction object
						XmlSchemaSimpleTypeRestriction restriction=st.Content as 
XmlSchemaSimpleTypeRestriction;
						if (restriction != null)
						{
							restriction.BaseTypeName=new XmlQualifiedName(typeName, nameSpace);
							CompileSchema();
							cbGlobalTypes.SelectedIndex=-1;
						}
					}
				}
				// is it a complex type?
				else if (obj is XmlSchemaComplexType)
				{
					// if we're changing the name:
					if (name != null)
					{
						((XmlSchemaComplexType)obj).Name=name;
						CompileSchema();
					}
					// there is no such thing as changing the type of a complex type
				}
			}
		}
		
		bool AddFacet(XmlSchemaFacet facet, string val, TreeViewImages imgIdx)
		{
			// get the simple type.
			XmlSchemaSimpleType st=tvSchema.SelectedNode.Tag as XmlSchemaSimpleType;

			// assume failure
			XmlSchemaSimpleTypeRestriction rs=null;
			bool success=false;

			// if the simple type exists, get the restriction type
			if (st != null)
			{
				rs=st.Content as XmlSchemaSimpleTypeRestriction;
			}

			// if the restriction type exists...
			if (rs != null)
			{
				// create the node and add it to the facet collection
				TreeNode newNode=CreateNode(facet.ToString());
				facet.Value=val;
				rs.Facets.Add(facet);
				CompileSchema();
				success=true;
			}
			return success;
		}
		
		public static XmlNode[] TextToNodeArray(string text) 
		{
			XmlDocument doc = new XmlDocument();
			return new XmlNode[1] {doc.CreateTextNode(text)};
		}
		
		private void DecodeSchema(XmlSchema schema, TreeNode node)
		{
			try
			{
				DecodeSchema2(schema, node);
			}
			catch(Exception err)
			{
				edSchemaErrors.Text=err.ToString();
			}
		}

		
		
	}
}
When i open my xml file using this editor and click on any element in the 
tree view, the following error is displayed.
Type 'bookstoreType' is not declared.
Type 'authorName' is not declared.
Type 'bookType' is not declared.
Actually i got this code from code project. Can anyone help me in fixing 
this error.

Thanks.






0
Priya7318 (23)
11/14/2007 5:28:00 AM
dotnet.xml 7266 articles. 0 followers. Follow

0 Replies
674 Views

Similar Articles

[PageSpeed] 51

Reply:

Similar Artilces:

XML serialization , validating against multiple schemas
Hi My web service receives an object of type say MyObject. I want to serialize this object,and then validate the xml against the main xsd. When validation happens, it should also validate against the included schema. The main schema includes one more schema and the actual types are described in the included schema. eg., <xs:schema xmlns:t="http://myschemas/base" xmlns=""> <xs:import schemaLocation="base.xsd" /> <xs:element name="MyObject"> <xs:complexType> <xs:sequence minOccurs="0"> <xs:element name=&...

MSCOMCTL.OCX runtime error
I am trying to use an older program (developed probably around 2003/4). When I attempt to run it I get the following message: > > Run-time error '339': > > Component 'MSCOMCTL.OCX' or one of its dependencies not correctly > registered: a file is missing or invalid > I found this website from google, this specific thread: http://forums.techarena.in/vista-help/845481.htm so I decided to try doing what was suggested in that thread. None of the things that were suggested helped, then it mentioned something about dependency walker. I opened the ...

i get error 404 not found when trying to download
I'm trying to download nokia pc suite to windows xp to upload gallery onto the computer but get error message404 not found - how can i download this pc suite please -- Krysy Albutt Krysy Albutt wrote: > I'm trying to download nokia pc suite to windows xp to upload gallery > onto the computer but get error message404 not found - how can i > download this pc suite please Care to enlighten us how this pertains to: - 1) Microsoft 2) Publisher 3) Windows If you're having problems downloading from the *NOKIA* site where do you think you should be directing your ...

How to get Calendar to send me reminders
I have changed my e-mail address but for some reason I cannot get Calendar to send reminders to my new address - I think I have carried out all that is necessary to effect the changover but I am not getting reminders sent. Can anyone help please? Is the Calendar Live ID based and accessible at Calendar.live.com ? -- ....winston ms-mvp mail "Dabardevon" wrote in message = news:FDC2B3B2-EDE4-41B1-BFC4-C0F9ED59CFB9@microsoft.com... I have changed my e-mail address but for some reason I cannot get = Calendar to send reminders to my new address - I think I have...

Q: How to automatically adapt column width with XML format?
Hi. I'm developing an application that outputs its results to an XML file (with Excel XP's DTD). The trouble is the column width, which is set at default. Is there an XML tag which allow to adapt width automatically? I thought about a VBA macro, but I noticed that VBA code isn't stored in XML Excel's files. Thanks in advance, Francesco. ...

Some recipients get the attachment, some get winmail.dat
This one has me baffled. We are using Exchange 2000 and Outlook 2000 and have been for 8 months. No previous problems with attachments (.doc, .xls, .jpg). About 2 weeks ago, we started hearing from certain recipients that the attachment wasn't arriving; instead they were getting an unreadable file called winmail.dat. MS says that this is because the sender is using Rich Text to format the email. We have changed the senders to use Plain Text and still have the same problem. If the email is sent to several recipients, some will get the attachment fine, some will not. This didn'...

How to get the CScrollBar's Handle in CTreeCtrl?
Hey,All: I thought I have a problem when I trid to get the CScrollBar's handle from my CTreeCtrl extended handle. Can anybody tell me whether I can get the handle of the CScrollBar from the CTreeCtrl? Thanks in advance! Carl :-| Carl wrote: > Hey,All: > > I thought I have a problem when I trid to get the CScrollBar's handle from > my CTreeCtrl extended handle. > Can anybody tell me whether I can get the handle of the CScrollBar from the > CTreeCtrl? > > Thanks in advance! > Carl > :-| > > Sorry, it is not that simple. The scroll bars that...

Outlook 2003 error #16
My PC crashed last night, and when I restarted it, Outlook 2003 gave an error message that the personal folders had been improperly terminated, and it was trying to recover. That message disappeared after a few seconds, and a normal-looking Outlook window came up. But now, when I try to send/recieve email, I get the error message: Task 'Verizon Main - Receiving' reported error (0x80040600) : 'Unknown Error 0x80040600' Is there a way to recover Outlook without losing the inbox, which contains numerous unread emails? Running Vista Home Premium edition. In the first in...

Unhandled Exception error on few accounts
Hello, On just a few accounts, if I go to History or Activities, I get the following unhandled exception: [SoapException: Server was unable to process request.] System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall) +1496 System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) +218 Microsoft.Crm.Platform.Proxy.ActivityPointerWebService.RollupByObject(Guid rollupById, String rollupByName, RollupType rollupType, QueryBase queryExpress...

A Crystal Beginner
I am using Crystal 9.2.4.77 and have loaded the Crystal enhancements. Now I want to do against the CRM database. What do I do? I thought I would create a data source to the CRM SQLserver, which I did, then connect to it through Crystal Reports. That works, but when I drill down on the AAA_MSCRM database to choose my tables, it shows me dbo as the only option (where did this come from??) and under that are just a few generic tables. No CRM tables. Something's not quite right. What am I missing? file - log on to aps server "KBLawson" <klawson@aetinc.com> wrote in ...

Cannot get fast forward or fast reverse to work with WMP 11
I am running Vista Home Premium on a HP G 217-EM Notebook which comes pre-installed with Windows Media Player 11. When I play cds and try to fast forward or fast reverse by keeping the fast forward or fast reverse buttons constantly depressed nothing happens. Why is this, and can anyone come up with a solution? Many thanks This doesn't work on my system either, so it's probably just a limitation of WMP. Fast forward and fast reverse should work fine when you rip the CD's to MP3 or WMA files, and play these files instead. Regards -- Tim De Baets http://www....

GP 10 new install (trial)
Hello, I installed a trial version of GP 10 on a standalone PC to evaluate it. Install seems to complete without problem (includes SQL 2005 install) but when I first want to run Utilities I get an error message " an error occurred while using the bcp utility - data was not correctly copied to the server..." It says it's either a BCP install or ODBC issue. Re-installed everything, same result. Would anybody have a clue? This problem occurs if the User Account Control (UAC) feature is enabled in Windows Vista. However, you must disable the UAC feature if you want to run M...

Combo Box Yes/No error
Hello. I have a form that I want to add a function in the footer that will allow me to sort the records based on whether they are active or inactive. The field in my table is a yes/no check box that is check for yes and unchecked for no. I have tried to use a combo box with 2 columns, Active and Inactive with corresponding fields yes/no check boxes. I set it up as a 2 column count combo box and hid the yes/no column so active/inactive would appear. I get an error that the expression is too complex.... The information is passed to my query to the Active Yes/No column by using: [Forms]![E...

"Compile error in hidden module: GlobalCodeModule"
Hi, we have 3 versions of office installed 2003, 2007, 2010. We have had no problems with that until a week ago or so. In Word 2003 we have code in a global template which uses a treeview control from mscomctl.ocx. I'm not sure that this is the problem though. I have tried to uncheck the reference to theat control and save the template, but then I get another error message "The disk is full. etc etc". I can't save the template after removing the reference or doing any other editing in that template. This not only occurring on my computer. I suspect a rec...

Get paid while you get online!!
I found a great Internet company - Cashfiesta.com - that has created a product everyone can benefit from. They pay you while you work or play on your computer. All you need to do is keep their software - the FiestaBar=99 - active while you are online. They even pay you when your friends are using their computers. Unlike other companies, Cashfiesta gives you control over how much money you earn. They have an individual payrate based on the number of Special Offers you sign up for. As some of these offers are free, you can increase your payrate up to 33 times without spending a penny. It's...

Can't get auto-update (update) to install
Version: 2008 Operating System: Mac OS X 10.4 (Tiger) Processor: Power PC I've been trying to manually check for updates to Word 2008, and I get a &quot;critical update&quot; notice, asking me to install auto-update. When I try to install it, I cannot. It just keeps repeating the attempt, in an &quot;endless loop.&quot; What to do? <br> Thank you. ...

help reading xml doc
I'm new to XML, so please bear with me. I'm using XPathNavigator and XPathNodeIterator to return a set of xml nodes from a document that looks like this: <root> <book title="Some Title"> <chapter> <title>Chapter 1</title> <starting_page>34</starting_page> <number_of_pages>15</number_of_pages> </chapter> <chapter> <title>Chapter 2</title> <starting_page>50</starting_page> <number_of_pages>15</number_of_pa...

Spreadsheet getting corrupted
Hello All: I have a relatively large spreadsheet. I am getting errors (see after my signature line). What could be causing these errors? Is it that the spreadsheet is too large? Thanks Deguza -------------------------------------------------------- Microsoft Office Excel File Repair Log Errors were detected in file 'C:\Documents and Settings\deguza\My Documents\sales\Sales_2006_2007.xls' The following is a list of repairs: Global PivotTable report information was repaired due to integrity problems. Global PivotTable report information was repaired due to integrity problems. Glo...

Reg getting the next IV Document Number field !
Hi, I am creating a window in dexterity similar to the item transaction entry window (Transactions>Inventory> Transaction Entry). In the Item transaction Entry window, the Document number field defaults to the next document number when we move the focus to that field. I wanted to know if there is any function , or table that i can access to get the next document number in the new window that i am creating. Thanks, swetha -- swetha >In the Item transaction Entry window, the Document number field defaults to the next document number when we move the focus to that field.< T...

How do I get??
Sorry if this seems a fairly easy question to you guys. I have a spreadsheet and I need to get the current system time into a cell. The format of the time is hh:mm am/pm. Any assistance would be most helpful. Hi try =INT(NOW()) in this cell and format is to your needs -- Regards Frank Kabel Frankfurt, Germany PM wrote: > Sorry if this seems a fairly easy question to you guys. > > I have a spreadsheet and I need to get the current system time into a > cell. The format of the time is hh:mm am/pm. > > Any assistance would be most helpful. PM, in the cell you want pu...

Get notified when Out of Office is on
I am using Outlook 2007. With 2003, when returning from leave, I used to get a notification that the Outlook out of office was still on and asking me if I wanted to switch it off. This reminder no longer appears with 2007. How can I switch this setting on so that I get the notification? "Mary Ann" <MaryAnn@discussions.microsoft.com> wrote in message news:ED5533A7-D0EA-41B8-B1A0-A9D15FB6FD98@microsoft.com... >I am using Outlook 2007. With 2003, when returning from leave, I used to get > a notification that the Outlook out of office was still on and asking me ...

Error 3314
I previously set a property to True in a subform field in order to prevent users from leaving a Null value. Error 3314 appears when trying to click in the field to enter information. So, you can't even do what the error message is asking you to do. In addition to that, you can't click anywhere else in the main form until Error 3314 is dealt with (trapped!). I don't really have time to deal with this problem, so I decided to just not make it a required field (setting No instead of Yes in design view). Nothing changed! I've even refreshed the tables and this subform ...

over VPN, it gets stuck when sending outgoing email
When I use VPN to connect to work from home, the outlook can not finish sending outgoing emails. The progress bar moves to the end but then stops there forever. It can never finish. The receiving of new incoming emails work fine. All other network functionality works, e.g. internet browsing, telnet, ftp, etc, all work fine. My system is win2k. I use linksys wireless DSL router. I'd appreciate any hint! Are you using Exchange server? I'd set up your mail profile to prompt you to work offline or online - when using VPN, work offline with scheduled syncs. If not using exchange, pos...

Error -2147024773 when changing passwords in OWA
Hi, Mac clients cant seem to change their Windows password using OWA. The error number -2147024773 appears during the password change process. Can anyone help? Other information: Exchange Server 2003/Windows Server 2003 in mixed mode: with SSL installed and the "Change Password Feature in Outlook Web Access" enabled (KB327134) Macs: OS 9 using IE4.5 and IE5. Windows PCs can change passwords without problem. Intermittently I can change the password on the IE4.5 Mac but most of the time I get the error above. Thanks, Martin Can user's who are using a PC change their domain...

Server error in '/' Application 08-16-03
When I want to save some information (web based) like a quick Contact, I receive the following error: Server Error in '/' application. A potentially dangerous Request.Form value was detected from the client ............ anyone an idea ? Thx Hi Everyone, I was having the same error when trying to edit my Business Unit(New Install). I tried your suggested fix but now I cannot open the CRM app from the browser (server nor client) It opens up the IIS default page. How can I correct this? Help!!! Thanks, Jaime >-----Original Message----- >You need to uninstall the 1.1 .N...