예제 #1
0
function formCurrentXmlPath(&$path, $nodeName, $actionType)
{
    //The path of the current node ir formed.
    //By default, the string [1] is attached to all node names
    //if there are more siblings, this number is incremented, if not, remains the same:
    switch ($actionType) {
        case INSERT_NEW_CHILD:
            $path = $path . "/" . $nodeName . "[1]";
            break;
        case SWITCH_TO_SIBLING:
            $pos = strrpos($path, "/");
            $posEnd = strrpos($path, "[");
            $currentSiblingName = substr($path, $pos + 1, $posEnd - $pos - 1);
            if ($currentSiblingName === $nodeName) {
                $currentSiblingName = substr($path, $pos + 1);
                $siblingCount = getDataBetweenTokens($currentSiblingName, "[", "]");
                $path = substr($path, 0, $pos);
                $path = $path . "/" . $nodeName . "[" . ($siblingCount[0] + 1) . "]";
            } else {
                //A different sibling, so remplace current:
                $path = substr($path, 0, $pos);
                $path = $path . "/" . $nodeName . "[1]";
            }
            break;
        case CHANGE_PARENT:
            $pos = strrpos($path, "/");
            $path = substr($path, 0, $pos);
            break;
    }
}
function getSchemaErrorLocation($errorElement)
{
    $locationString = $errorElement->getAttribute('location');
    $tok = strtok($locationString, "/*");
    $path = array();
    $path[] = $tok;
    while ($tok !== false) {
        $tok = strtok("/*");
        $path[] = $tok;
    }
    $postion = array();
    $completeElementPath = "";
    for ($i = 0; $i < sizeof($path); $i++) {
        $postion = getDataBetweenTokens($path[$i], "[", "]");
        if (sizeof($postion) === 1) {
            $completeElementPath = $completeElementPath . "/" . getLocalName($postion[0]) . "[1]";
        } else {
            if (sizeof($postion) === 2) {
                $completeElementPath = $completeElementPath . "/" . getLocalName($postion[0]) . "[" . $postion[1] . "]";
            } else {
                //Error
            }
        }
    }
    return $completeElementPath;
}