XML-Schema

 view release on metacpan or  search on metacpan

docs/html/modules/XML/Schema/Attribute.html  view on Meta::CPAN


# hash ref of arguments
my $attr = XML::Schema::Attribute->new( {
    name      => 'bar', 
    type      => XML::Schema::Type::string->new(),
    scope     => $complex_type,
    default   => 20,
    namespace => 'http://tt2.org/XML/Example.xml',
} ) || die XML::Schema::Attribute-&gt;error();</b></pre></ul>

  
<hr width="100%" size="1" noshade="1"><a name="section_Description"><h2>Description</h2></a>
    <p>
    This module implements an object class for representing XML
    attributes with XML Schema.  An attribute is, of course, a
    '<code><b>name=&quot;value&quot;</b></code>' pair within the starting tag of an
    XML element.  In the following example, the attributes are named
    '<code><b>id</b></code>' and '<code><b>name</b></code>'.
    </p>


<p>
<ul>
<b><pre>
&lt;user id=&quot;lwall&quot; name=&quot;Larry Wall&quot;&gt;
    ...
&lt;/user&gt;
</pre></b>
</ul>
</p>

  
    <p>
    Attribute are defined as having a specific type which determines
    what the acceptable values can be.  These types are implemented by
    various objects derived from the
    <a href="../../../modules/XML/Schema/Type/Simple.html">XML::Schema::Type::Simple</a> module.  There are over
    30 inbuilt simple type, defined in the
    <a href="../../../modules/XML/Schema/Type/Builtin.html">XML::Schema::Type::Builtin</a> module, and which
    include things like string, integer, float, time, date, and so on.
    Furthermore, you can extend these basic types to create your own
    custom simple types by applying additional <a href="../../../modules/XML/Schema/Facet.html">validation facets</a>. 
    </p>


    <p>
    An attribute can also define default and fixed values for itself.
    A fixed constraint specifies a value that the attribute must have,
    if present in a particular instance document.  A default value can 
    be specified for attributes that are missing.
    </p>


    <p>
    An attribute can be defined within a particular scope.  Usually,
    it is within the definition of a <a href="../../../modules/XML/Schema/Type/Complex.html">complex type</a>, but can 
    also exist within an <a href="../../../modules/XML/Schema/Attribute/Group.html">attribute group</a>.
    The attribute communicates with its enclosing scope to resolve
    its type name (e.g. 'string') with a type object.  This allows 
    types to effectively be used before they are defined, and also 
    for attributes to be relocated for use in different scope (e.g.
    as part of an attribute group) and to resolve the correct type
    in each location.
    </p>

    
  

<hr width="100%" size="1" noshade="1"><a name="section_Methods"><h2>Methods</h2></a><ul>
<li><p>
<a name="method_new"><b>new()</b></a>
<br>


      <p>
        Constructor method called to create a new attribute object.  A
        list of '<code><b>key => value</b></code>
' pairs can be
        specified as command line arguments, or alternately, a hash
        reference can be passed which contains these configuration
        values.  The method returns a newly instantiated object on
        success.  On error it returns undef and sets an internal error
        message which can be retrieved by calling <a href="../../../modules/XML/Schema/Base.html#method_error"><code><b>error()</b></code></a> as a class method.

<ul><pre><p># list of options
my $attr = XML::Schema::Attribute-&gt;new( name =&gt; 'foo', type =&gt; 'string' )
    || die XML::Schema::Attribute-&gt;error();

# hash ref of options
my $attr = XML::Schema::Attribute-&gt;new( {
    name =&gt; 'foo', 
    type =&gt; 'string',
} ) || die XML::Schema::Attribute-&gt;error();</b></pre></ul>

      </p>


      <p>
        The following configuration options may be specifed:
      </p>


      <p>
<!-- table -->
<table border="0" cellpadding="4" cellspacing="1" 
       bgcolor="#000044">
<!-- table content -->
<tr bgcolor="#ccccff">
<td><b><small>Name</b></td><td><b><small>Typical Values</b></td><td><b><small>Description</b></td></tr>

        <tr valign="top" bgcolor="#eeeeff">
  <td>
    <a name="config_name"><code><b>name</b></code></a>
  </td>
  <td>
    <code><b>'myattr'</b></code>
  </td>
  <td>

	    The name of the attribute.  In the XML fragment <code><b>&lt;foo bar=&quot;baz&quot;/&gt;</b></code>
            the attribute name is '<code><b>bar</b></code>'.  This item is mandatory.



( run in 0.596 second using v1.01-cache-2.11-cpan-5511b514fd6 )