Skip to content

Commit

Permalink
Added root element detection
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.php.net/repository/pear/packages/File_Infopath/trunk@252826 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information
David Sanders committed Feb 13, 2008
1 parent 11483e7 commit d162d95
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions Infopath.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ class File_Infopath
*/
private $_submit = array();

/**
* Name of the root group, usually set to "myFields" by Infopath
*
* @access private
* @var string
*/
private $_root_element;

/**
* Constructor
*
Expand All @@ -135,15 +143,26 @@ public function __construct($filename)
// Instantiate the Cabinet reader
$this->_cab = new File_Cabinet($filename);

// Read manifest.xsf and obtain the list of views
// Read manifest.xsf to obtain information about the form
$manifest = new DOMDocument;
$manifest->loadXML($this->_cab->extract('manifest.xsf'));

$xpath = new DOMXPath($manifest);

// Root element[]
$list = $xpath->query('//xsf:package/xsf:files/xsf:file[@name="myschema.xsd"]/xsf:fileProperties/xsf:property[@name="rootElement"]/@value');
if ($list->length === 0) {
throw new File_Infopath_Exception('Error reading document');
}
$this->_root_element = $list->item(0)->value;

// Obtain the list of views
foreach ($manifest->getElementsByTagNameNS(self::XSF_NAMESPACE, 'view') as $view) {
$mainpane = $view->getElementsByTagNameNS(self::XSF_NAMESPACE, 'mainpane')->item(0);
$this->_views[$view->getAttribute('name')] = $mainpane->getAttribute('transform');
}

// obtain any submit information, if available
// Obtain any submit information, if available
$element = $manifest->getElementsByTagNameNS(self::XSF_NAMESPACE, 'submit')->item(0);
if (!is_null($element)) {
$http_handler = $element->getElementsByTagNameNS(self::XSF_NAMESPACE, 'useHttpHandler')->item(0);
Expand Down Expand Up @@ -335,8 +354,8 @@ public function getSchema()
$field_name = $element->getAttribute('name');
$type = $element->getAttribute('type');

if ($field_name !== 'myFields' &&
$field_name !== '' &&
if ($field_name !== $this->_root_element &&
$field_name !== '' &&
$type !== '') {
$attributes = array(
'default' => null,
Expand All @@ -363,7 +382,7 @@ public function getSchema()
// (Also available from sampledata.xml)
$template = new DOMDocument;
$template->loadXML($this->_cab->extract('template.xml'));
$my_fields = $template->getElementsByTagName('myFields')->item(0);
$my_fields = $template->getElementsByTagName($this->_root_element)->item(0);
$my_namespace = $my_fields->getAttribute('xmlns:my');
foreach ($my_fields->getElementsByTagNameNS($my_namespace, '*') as $element) {
if ($element->textContent !== '') {
Expand Down Expand Up @@ -409,7 +428,7 @@ public function getSchema()
}

// checkbox options
if ($this->)
// if ($this->)

return $schema;
}
Expand Down

0 comments on commit d162d95

Please sign in to comment.