src/SimpleDOM.php
public function getXpathStringForAttributeValue($attributeValue)
    {
        $hasApos = strpos($attributeValue, "'");
        $hasQuote = strpos($attributeValue, '"');

        if ($hasApos === false) {
            return "'" . $attributeValue . "'";
        }
        if ($hasQuote === false) {
            return '"' . $attributeValue . '"';
        }

        $result = 'concat(';
        $currentArgument = '';
        for ($pos = 0; $pos < strlen($attributeValue); $pos++) {
            switch (substr($attributeValue, $pos, 1)) {
                case "'":
                    $result .= '"';
                    $result .= $currentArgument;
                    $result .= "'\",";
                    $currentArgument = '';
                    break;
                case '"':
                    $result .= "'";
                    $result .= $currentArgument;
                    $result .= "\"',";
                    $currentArgument = '';
                    break;
                default:
                    $currentArgument .= substr($attributeValue, $pos, 1);
                    break;
            }
        }
        if (strlen($currentArgument) === 0) {
            $result = substr($result, 0, -1) . ')';
        } else {
            $result .= "'";
            $result .= $currentArgument;
            $result .= "')";
        }
        return $result;
    }
public function getXpathStringForAttributeValue($attributeValue)
    {
        $hasApos = strpos($attributeValue, "'");
        $hasQuote = strpos($attributeValue, '"');

        if ($hasApos === false) {
            return "'" . $attributeValue . "'";
        }
        if ($hasQuote === false) {
            return '"' . $attributeValue . '"';
        }

        $result = 'concat(';
        $currentArgument = '';
        for ($pos = 0; $pos < strlen($attributeValue); $pos++) {
            switch (substr($attributeValue, $pos, 1)) {
                case "'":
                    $result .= '"';
                    $result .= $currentArgument;
                    $result .= "'\",";
                    $currentArgument = '';
                    break;
                case '"':
                    $result .= "'";
                    $result .= $currentArgument;
                    $result .= "\"',";
                    $currentArgument = '';
                    break;
                default:
                    $currentArgument .= substr($attributeValue, $pos, 1);
                    break;
            }
        }
        if (strlen($currentArgument) === 0) {
            $result = substr($result, 0, -1) . ')';
        } else {
            $result .= "'";
            $result .= $currentArgument;
            $result .= "')";
        }
        return $result;
    }
Return a string to be used as xpath attribute search string.
This function is necessary because xpath can not by default find strings which contain a single AND a double quote.
Usage:

<code>
$object->xpath('element[\@name='.getXpathStringForAttributeValue('test').']');
</code>

@param $attributeValue
@return string