src/Misc/EFTools/XmlCore/Model/Validation/AttributeContentValidator.cs
/// <summary>
///     Returns the XmlSchemaType for the given node.
/// </summary>
/// <param name="attributePath"></param>
/// <returns></returns>
Returns the XmlSchemaType for the given node.
Returns the XmlSchemaType for the given node .
protected XmlSchemaType GetTypeNameForNode(AttributePath attributePath)
        {
            if (attributePath == null)
            {
                throw new ArgumentNullException("attributePath");
            }
            var attributePathCopy = attributePath.Clone();
            if (attributePathCopy.Count < 1)
            {
                return null;
            }
            var curr = attributePathCopy.PopFront();
            var schemaElement = GetXmlSchemaObject(SchemaSet.GlobalElements, curr.qname) as XmlSchemaElement;
            if (schemaElement == null)
            {
                Debug.Fail("Unable to find Global Schema Element " + curr.qname);
                return null;
            }
            var schemaType = GetXmlSchemaTypeFromXmlSchemaElement(schemaElement);
            if (schemaType == null)
            {
                Debug.Fail("Unable to find schema type for schema element " + curr.qname);
                return null;
            }
            while (attributePathCopy.Count > 0)
            {
                curr = attributePathCopy.PopFront();
                var xsct = schemaType as XmlSchemaComplexType;
                if (xsct != null)
                {
                    if (curr.type == AttributePath.QNameNodeTypePair.NodeType.Element)
                    {
                        XmlSchemaElement xe = null;
                        while (xe == null
                               && xsct != null)
                        {
                            xe = GetXmlSchemaElementFromParticle(xsct.Particle, curr.qname);
                            if (xe == null)
                            {
                                xe = GetXmlSchemaElementFromParticle(xsct.ContentTypeParticle, curr.qname);
                            }
                            if (xe == null)
                            {
                                xsct = xsct.BaseXmlSchemaType as XmlSchemaComplexType;
                            }
                        }
                        if (xe == null)
                        {
                            Debug.Fail("didn't find XmlSchemaElement for qname " + curr.qname + " in type " + schemaType.QualifiedName);
                            return null;
                        }
                        else
                        {
                            schemaType = GetXmlSchemaTypeFromXmlSchemaElement(xe);
                        }
                    }
                    else
                    {
                        var xa = GetXmlSchemaObject(SchemaSet.GlobalAttributes, curr.qname) as XmlSchemaAttribute;
                        if (xa == null)
                        {
                            xa = GetXmlSchemaAttributeFromXmlSchemaGroupBase(xsct, curr.qname);
                        }
                        if (xa == null)
                        {
                            Debug.Fail(
                                "didn't find XmlSchemaAttribute for qname " + curr.qname + " in Global Attributes or in type "
                                + xsct.QualifiedName);
                            return null;
                        }
                        else
                        {
                            schemaType = GetXmlSchemaTypeFromXmlSchemaAttribute(xa);
                        }
                    }
                }
                else
                {
                    Debug.Fail("not yet implemented!");
                }
            }
            return schemaType;
        }
protected XmlSchemaType GetTypeNameForNode ( AttributePath attributePath ) { if ( attributePath == null ) { throw new ArgumentNullException ( " " ) ; } var attributePathCopy = attributePath . Clone ( ) ; if ( attributePathCopy . Count < 1 ) { return null ; } var curr = attributePathCopy . PopFront ( ) ; var schemaElement = GetXmlSchemaObject ( SchemaSet . GlobalElements , curr . qname ) as XmlSchemaElement ; if ( schemaElement == null ) { Debug . Fail ( " " + curr . qname ) ; return null ; } var schemaType = GetXmlSchemaTypeFromXmlSchemaElement ( schemaElement ) ; if ( schemaType == null ) { Debug . Fail ( " " + curr . qname ) ; return null ; } while ( attributePathCopy . Count > 0 ) { curr = attributePathCopy . PopFront ( ) ; var xsct = schemaType as XmlSchemaComplexType ; if ( xsct != null ) { if ( curr . type == AttributePath . QNameNodeTypePair . NodeType . Element ) { XmlSchemaElement xe = null ; while ( xe == null && xsct != null ) { xe = GetXmlSchemaElementFromParticle ( xsct . Particle , curr . qname ) ; if ( xe == null ) { xe = GetXmlSchemaElementFromParticle ( xsct . ContentTypeParticle , curr . qname ) ; } if ( xe == null ) { xsct = xsct . BaseXmlSchemaType as XmlSchemaComplexType ; } } if ( xe == null ) { Debug . Fail ( " " + curr . qname + " " + schemaType . QualifiedName ) ; return null ; } else { schemaType = GetXmlSchemaTypeFromXmlSchemaElement ( xe ) ; } } else { var xa = GetXmlSchemaObject ( SchemaSet . GlobalAttributes , curr . qname ) as XmlSchemaAttribute ; if ( xa == null ) { xa = GetXmlSchemaAttributeFromXmlSchemaGroupBase ( xsct , curr . qname ) ; } if ( xa == null ) { Debug . Fail ( " " + curr . qname + " " + xsct . QualifiedName ) ; return null ; } else { schemaType = GetXmlSchemaTypeFromXmlSchemaAttribute ( xa ) ; } } } else { Debug . Fail ( " " ) ; } } return schemaType ; }
Returns the XmlSchemaType for the given node.
Returns the XmlSchemaType for the given node .
// prime the pump.  The first node on the stack should be a global element. // check the content type particle // check the base type // we need to find an attribute // see if it is a global attribute first // if that doesn't work try to see whether it's an attribute on the XmlSchemaComplexType xsct
None
attributePath
AttributePath
None