Previous Up Next


p:load

p:load — Loads a document from a URI.

Synopsis

<p:declare-step type="p:load">
     <p:output port="result"/>
     <p:option name="href" required="true"/>                       <!-- anyURI -->
     <p:option name="dtd-validate" select="'false'"/>              <!-- boolean -->
</p:declare-step>

Description

The p:load step loads the document specified in the href option. The p:load step is the same as p:document except that the URI can be computed dynamically and DTD validation can be requested:

When dtd-validate is true, the processor uses a validating parser. A validating parser performs DTD validation; if you want to perform RELAX NG or XML Schema validation, use the p:validate-with-relax-ng or p:validate-with-xml-schema steps, respectively.

Errors

Error Description
err:C0027 Occurs if the document is not valid or the step doesn't support DTD validation.

Examples

In this example, we load a document specified in an option.

  1 <p:pipeline xmlns:p="http://www.w3.org/ns/xproc"
                version="1.0">
    
      <p:option name="href" select="'../docs/document.xml'"/>
  5 
      <p:load>
        <p:with-option name="href" select="$href"/>
      </p:load>
    </p:pipeline>
Output
1 <document>
<para>This is a paragraph of text.</para>
<para>So is this</para>
</document>

This time we'll load a document that includes a DTD.

  1 <!DOCTYPE doc [
    <!ELEMENT doc (p+)>
    <!ELEMENT p (#PCDATA)*>
    ]>
  5 <doc>
    <p>I'm valid!</p>
    </doc>

This document is valid.

  1 <p:pipeline xmlns:p="http://www.w3.org/ns/xproc"
                version="1.0">
    
      <p:option name="href" select="'../docs/valid.xml'"/>
  5 
      <p:load dtd-validate="true">
        <p:with-option name="href" select="$href"/>
      </p:load>
    </p:pipeline>
Output
1 <doc>
<p>I'm valid!</p>
</doc>

As we've seen in other examples, p:try/p:catch can be used to recover from dynamic errors. In this example, we attempt to load a valid document. If the document isn't valid, we load it anyway, but add an attribute to the root element (so that subsequent pipeline processing can tell, presumably).

This document also includes a DTD:

  1 <!DOCTYPE doc [
    <!ELEMENT doc (p+)>
    <!ELEMENT p (#PCDATA)*>
    ]>
  5 <doc>
    <para>I'm not valid!</para>
    </doc>

But it is not valid. (a para appears where a p is expected.)

  1 <p:pipeline xmlns:p="http://www.w3.org/ns/xproc"
                version="1.0">
    
      <p:option name="href" select="'../docs/invalid.xml'"/>
  5 
      <p:try>
        <p:group>
          <p:load dtd-validate="true">
            <p:with-option name="href" select="$href"/>
 10       </p:load>
        </p:group>
        <p:catch>
          <p:load dtd-validate="false">
            <p:with-option name="href" select="$href"/>
 15       </p:load>
          <p:add-attribute match="/*" attribute-name="INVALID"
                           attribute-value="document-failed-dtd-validation"/>
        </p:catch>
      </p:try>
 20 </p:pipeline>
Output
1 <doc INVALID="document-failed-dtd-validation">
<para>I'm not valid!</para>
</doc>