You are here

function patterns_xmlparser_parse in Patterns 7

Same name and namespace in other branches
  1. 7.2 patterns_xmlparser/patterns_xmlparser.module \patterns_xmlparser_parse()

Creates a pattern from an XML data source.

Parameters

string $xml The XML string of the data source.:

Return value

array|bool The pattern structure, or FALSE.

1 call to patterns_xmlparser_parse()
patterns_xmlparser_load in patterns_xmlparser/patterns_xmlparser.module
Loads an XML pattern file without validating.

File

patterns_xmlparser/patterns_xmlparser.module, line 43

Code

function patterns_xmlparser_parse($xml) {
  $parse = drupal_xml_parser_create($xml);
  xml_parser_set_option($parse, XML_OPTION_CASE_FOLDING, 0);
  if (!xml_parse_into_struct($parse, $xml, $vals, $index)) {

    // TODO: Report parsing or other error.
    return FALSE;
  }

  // Create a multi-dimensional array representing the XML structure.
  $pattern = current(_patterns_xmlparser_parse_tag($vals));
  if (empty($pattern) || $pattern['xml_tag'] != 'pattern') {

    // TODO: Error reporting.
    return FALSE;
  }

  // Rearrange the data in a nice way for each component.
  // Make sure actions are processed differently so order is preserved.
  $pattern = patterns_xmlparser_rearrange_data($pattern);
  return $pattern;
}