std::vector< Result > AllowedChildrenValidator::ValidateAllowedChildren( 
    const QName &parent_qname, 
    const std::vector< QName > &allowed_children, 
    const xc::DOMDocument &document )
{
    xc::DOMNodeList *parents_matching = document.getElementsByTagNameNS(
        toX( parent_qname.namespace_name ),  toX( parent_qname.local_name ) );

    std::vector< Result > results;

    if ( parents_matching->getLength() < 1 )
    
        return results;    

    xc::DOMElement* parent = static_cast< xc::DOMElement* >( parents_matching->item( 0 ) );
    std::vector< xc::DOMElement* > children = xe::GetElementChildren( *parent );

    for ( uint i = 0; i < children.size(); ++i )
    {
        xc::DOMElement *child = children[ i ];
        QName child_qname( fromX( child->getLocalName() ), fromX( child->getNamespaceURI() ) );

        if ( !Util::Contains< QName >( allowed_children, child_qname ) )

            results.push_back( NotAllowedChildResult( *children[ i ] ) );
    }

    return results;
}
Ejemplo n.º 2
0
std::vector< Result > IdsUnique::ValidateXml(
    const xc::DOMDocument &document,
    const fs::path& )
{
    xc::DOMNodeList *elements = document.getElementsByTagName( toX( "*" ) );

    boost::unordered_set< std::string > ids;
    std::vector< Result > results;

    for ( uint i = 0; i < elements->getLength(); ++i )
    {
        xc::DOMElement *element = static_cast< xc::DOMElement* >( elements->item( i ) );
        std::string id = fromX( element->getAttribute( toX( "id" ) ) );

        if ( !id.empty() )
        {
            if ( ids.count( id ) == 0 )
            {
                ids.insert( id );
            }

            else
            {
                results.push_back( 
                    ResultWithNodeLocation( ERROR_XML_ID_NOT_UNIQUE, *element )
                    .AddMessageArgument( id ) 
                    );
            }
        }
    }

    return results;
}
Ejemplo n.º 3
0
std::vector< Result > PackageIsRoot::ValidateXml(
    const xc::DOMDocument &document,
    const fs::path& )
{
    xc::DOMElement *root_element = document.getDocumentElement();

    std::vector< Result > results;

    if ( fromX( root_element->getLocalName() ) != "package" ) 
    {
        results.push_back( ResultWithNodeLocation( 
            ERROR_OPF_PACKAGE_NOT_ROOT, *root_element ) );
    }

    return results;
}
Ejemplo n.º 4
0
std::vector< Result > ElementPresentValidator::VerifyElementPresent( 
    const QName &element_qname, 
    const std::vector< QName > &possible_parents,
    const xc::DOMDocument &document )
{
    xc::DOMNodeList *matching_elements = document.getElementsByTagNameNS(
        toX( element_qname.namespace_name ),  toX( element_qname.local_name ) );

    std::vector< Result > results;

    if ( matching_elements->getLength() < 1 )
    {
        xc::DOMNode* parent = xe::GetFirstAvailableElement( possible_parents, document );

        Result result = parent != NULL                                                   ?
                        ResultWithNodeLocation( ERROR_XML_ELEMENT_NOT_PRESENT, *parent ) :
                        Result( ERROR_XML_ELEMENT_NOT_PRESENT );
                        
        result.AddMessageArgument( element_qname.local_name );
        results.push_back( result );
    }

    return results;
}