You are here

static function W3CvalidatorAPI::parseSOAP12Response in W3C Validator 7

* Parse an XML response from the validator * * This function parses a SOAP 1.2 response xml string from the validator. * *

Parameters

string $xml The raw soap12 XML response from the validator.: * * @return mixed object W3Cvalidator_Response | bool false

1 call to W3CvalidatorAPI::parseSOAP12Response()
W3CvalidatorAPI::validate in validators/W3CvalidatorAPI.php
* Validate the input URI. *

File

validators/W3CvalidatorAPI.php, line 88
W3CvalidatorAPI.php

Class

W3CvalidatorAPI
@file W3CvalidatorAPI.php

Code

static function parseSOAP12Response($xml) {

  // If the document the answer is correct : let's analyse it.
  $doc = new DOMDocument();
  if ($doc
    ->loadXML($xml)) {
    $response = new W3Cvalidator_Response();

    // Get the standard CDATA elements.
    foreach (array(
      'uri',
      'checkedby',
      'doctype',
      'charset',
    ) as $var) {
      $element = $doc
        ->getElementsByTagName($var);
      if ($element->length) {
        $response->{$var} = $element
          ->item(0)->nodeValue;
      }
    }

    // Handle the bool element validity.
    $element = $doc
      ->getElementsByTagName('validity');
    if ($element->length && $element
      ->item(0)->nodeValue == 'true') {
      $response->validity = true;
    }
    else {
      $response->validity = false;
    }

    // If response is invalid : get the errors corresponding.
    if (!$response->validity) {
      $errors = $doc
        ->getElementsByTagName('error');
      foreach ($errors as $error) {
        $response->errors[] = new W3Cvalidator_Message($error);
      }
    }
    $response->error_count = count($response->errors);

    // Get the eventual warnings.
    $warnings = $doc
      ->getElementsByTagName('warning');
    foreach ($warnings as $warning) {
      $response->warnings[] = new W3Cvalidator_Message($warning);
    }
    $response->warning_count = count($response->warnings);
    return $response;
  }
  else {

    // Could not load the XML.
    return false;
  }
}