示例#1
0
        private void expandReferences()
        {
            foreach (IXsdNode node in GetAllNodes())
            {
                if (node is IXsdHasAttribute)
                {
                    ICollection <XsdAttribute> col = ((IXsdHasAttribute)node).GetAttributes();
                    foreach (XsdAttribute xsdAttribute in col)
                    {
                        if (xsdAttribute.TypeTarget == null)
                        {
                            xsdAttribute.TypeTarget = getNodeByName(xsdAttribute.TypeName);
                        }
                    }
                }

                IXsdHasRef refable = node as IXsdHasRef;
                if (refable != null && refable.RefTarget == null)
                {
                    refable.RefTarget = getNodeByName(refable.RefName);
                }
                IXsdHasType typeable = node as IXsdHasType;
                if (typeable != null && typeable.TypeTarget == null)
                {
                    typeable.TypeTarget = getNodeByName(typeable.TypeName);
                }
                XsdExtension extension = node as XsdExtension;
                if (extension != null && extension.BaseTarget == null)
                {
                    extension.BaseTarget = getNodeByName(extension.Base);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Parses the schema and adds the found items to node
        /// </summary>
        /// <param name="schema"></param>
        /// <param name="node"></param>
        private void parse(XmlNode schema, XsdNode node)
        {
            XmlNodeList nl = schema.ChildNodes;

            for (int i = 0; i < nl.Count; i++)
            {
                XmlNode n = nl.Item(i);

                string name = n.Name;
                if (!name.StartsWith(_prefix))
                {
                    continue;
                }
                name = name.Substring(_prefix.Length);

                switch (name)
                {
                case "element":
                {
                    XsdNode newNode = new XsdElement(n);
                    node.AddKids(newNode);
                    parse(n, newNode);
                    break;
                }

                case "sequence":
                case "choice":
                case "all":
                {
                    XsdNode newNode = new XsdAllSequenceChoice(n, name);
                    node.AddKids(newNode);
                    parse(n, newNode);
                    break;
                }

                case "documentation":
                {
                    //last element
                    node.AddAnnotation(n.InnerText);
                    break;
                }

                case "attribute":
                {
                    XsdAttribute newAttr = new XsdAttribute(n);
                    ((IXsdHasAttribute)node).AddAtts(newAttr);
                    parse(n, newAttr);
                    break;
                }

                case "complexType":
                {
                    if (!string.IsNullOrEmpty(VisualizerHelper.GetAttr(n, "name")))
                    {
                        XsdComplexType newType = new XsdComplexType(n);
                        node.AddKids(newType);
                        parse(n, newType);
                    }
                    else
                    {
                        parse(n, node);
                    }
                    break;
                }

                case "simpleType":
                {
                    if (!string.IsNullOrEmpty(VisualizerHelper.GetAttr(n, "name")))
                    {
                        XsdSimpleType newType = new XsdSimpleType(n);
                        node.AddKids(newType);
                        parse(n, newType);
                    }
                    else
                    {
                        parse(n, node);
                    }
                    break;
                }

                case "annotation":
                {
                    parse(n, node);
                    break;
                }

                case "restriction":
                {
                    XsdNode newNode = new XsdRestriction(n);
                    node.AddKids(newNode);
                    parse(n, newNode);
                    break;
                }

                case "enumeration":
                {
                    string value = VisualizerHelper.GetAttr(n, "value");
                    ((XsdRestriction)node).AddEnum(value);
                    break;
                }

                case "pattern":
                {
                    string value = VisualizerHelper.GetAttr(n, "value");
                    ((XsdRestriction)node).Pattern = value;
                    break;
                }

                case "length":
                {
                    string value = VisualizerHelper.GetAttr(n, "value");
                    ((XsdRestriction)node).Length = value;
                    break;
                }

                case "maxLength":
                {
                    string value = VisualizerHelper.GetAttr(n, "value");
                    ((XsdRestriction)node).MaxLength = value;
                    break;
                }

                case "minLength":
                {
                    string value = VisualizerHelper.GetAttr(n, "value");
                    ((XsdRestriction)node).MinLength = value;
                    break;
                }

                case "maxInclusive":
                {
                    string value = VisualizerHelper.GetAttr(n, "value");
                    ((XsdRestriction)node).MaxInclusive = value;
                    break;
                }

                case "maxExclusive":
                {
                    string value = VisualizerHelper.GetAttr(n, "value");
                    ((XsdRestriction)node).MaxExclusive = value;
                    break;
                }

                case "minInclusive":
                {
                    string value = VisualizerHelper.GetAttr(n, "value");
                    ((XsdRestriction)node).MinInclusive = value;
                    break;
                }

                case "minExclusive":
                {
                    string value = VisualizerHelper.GetAttr(n, "value");
                    ((XsdRestriction)node).MinExclusive = value;
                    break;
                }

                case "notation":
                case "schema":
                case "appInfo":
                case "group":
                case "#comment":
                case "#text":
                case "key":
                case "keyref":
                case "unique":
                    //ignore
                    break;

                case "any":
                {
                    XsdNode newNode = new XsdAny(n);
                    node.AddKids(newNode);
                    parse(n, newNode);
                    break;
                }

                case "import":
                case "include":
                {
                    XsdNode newNode = new XsdImportInclude(n, name);
                    node.AddKids(newNode);
                    parse(n, newNode);
                    break;
                }

                case "complexContent":
                case "simpleContent":
                {
                    parse(n, node);
                    break;
                }

                case "extension":
                {
                    XsdNode newNode = new XsdExtension(n);
                    node.AddKids(newNode);
                    parse(n, newNode);
                    break;
                }

                case "anyAttribute":
                case "attributeGroup":
                case "field":
                case "list":
                case "redefine":
                case "selector":
                case "union":
                    Debug.Fail("Not supported: " + name);
                    Console.Error.WriteLine("Not supported: " + name);
                    break;

                default:
                    Debug.Fail("Unknown type: " + name);
                    break;
                }
            }
        }