Beispiel #1
0
    static void Main()
    {
        StreamReader sr  = new StreamReader("aschema.xml");
        XmlSchema    xs  = XmlSchema.Read(sr, ValidationCallBack);
        XmlSchemaSet xss = new XmlSchemaSet();

        xss.Add(xs);
        xss.Compile();
        Console.WriteLine("Query: ");
        string           q   = Console.ReadLine();
        XmlQualifiedName xqn = new XmlQualifiedName(q);

        if (xs.SchemaTypes.Contains(xqn))
        {
            object o = xs.SchemaTypes[xqn];
            if (o.GetType() == typeof(XmlSchemaComplexType))
            {
                results = deref_complex(xs, (XmlSchemaComplexType)o);
                results.print_children();
            }
        }
        else
        {
            Console.WriteLine("Not found!");
        }
    }
Beispiel #2
0
    static result_tree deref_complex(XmlSchema xs, XmlSchemaComplexType cplx)
    {
        result_tree rt = new result_tree(cplx.Name);

        if (cplx.Particle.GetType() == typeof(XmlSchemaSequence))
        {
            XmlSchemaSequence seq = (XmlSchemaSequence)cplx.Particle;
            foreach (object o in seq.Items)
            {
                if (o.GetType() == typeof(XmlSchemaElement))
                {
                    XmlSchemaElement elem = (XmlSchemaElement)o;
                    XmlQualifiedName name = elem.SchemaTypeName;
                    result_tree      branch;
                    object           referto = xs.SchemaTypes[name];
                    if (referto.GetType() == typeof(XmlSchemaComplexType))
                    {
                        branch           = deref_complex(xs, (XmlSchemaComplexType)referto);
                        branch.nodevalue = elem.Name;
                    }
                    else if (referto.GetType() == typeof(XmlSchemaSimpleType))
                    {
                        XmlSchemaSimpleType st = (XmlSchemaSimpleType)referto;
                        branch = new result_tree(elem.Name + " = " + deref_simple(st).ToString());
                    }
                    else
                    {
                        branch = null;
                    }
                    if (branch != null)
                    {
                        rt.children.Add(branch);
                    }
                }
            }
        }
        return(rt);
    }