Processes a calculation linkbase given SimpleXMLElement node
@param array $linkbaseRef
@param SimpleXMLElement $xml
@param string $xml_basename
@param string $usedOn
547318
private function processCalculationLinkbaseXml( $linkbaseRef, $xml, $xml_basename, $usedOn )
	{
		// Make sure this file contains calculation link elements so is valid for the role type
		if ( ! count( $xml->children( XBRL_Constants::$standardPrefixes[ STANDARD_PREFIX_LINK ] )->calculationLink ) )
		{
			if ( ! empty( $linkbaseRef['role'] ) && $linkbaseRef['role'] != XBRL_Constants::$anyLinkbaseRef )
			{
				$this->reportNoRoleLinks( $linkbaseRef, 'calculation' );
			}
			return;
		}

		$arcroleRefs = array();
		$taxonomy_base_name = $this->getTaxonomyXSD();

		foreach ( $xml->children( XBRL_Constants::$standardPrefixes[ STANDARD_PREFIX_LINK ] )->arcroleRef as $arcroleRefKey => $arcroleRef )
		{
			$attributes = $arcroleRef->attributes( XBRL_Constants::$standardPrefixes[ STANDARD_PREFIX_XLINK ] );
			$arcroleRefHref = (string) $attributes->href;

			// BMS 2015-04-26 This is neessary now linkbases defined in the schema document are supported
			// because a role reference to a type might be a relative reference to an id in the schema doc.
			$arcroleRefParts = explode( "#", $arcroleRefHref );
			if ( ! $arcroleRefParts )
			{
				$arcroleRefHref = $this->getTaxonomyXSD();
			}
			else if ( ! $arcroleRefParts[0] )
			{
				$arcroleRefParts[0] = $this->getTaxonomyXSD();
				$arcroleRefHref = implode( "#", $arcroleRefParts );
			}

			$arcroleUri = (string) $arcroleRef->attributes()->arcroleURI;
			$fragment = parse_url( $arcroleRefHref, PHP_URL_FRAGMENT );

			if ( XBRL::isValidating() )
			{
				if ( isset( $arcroleRefs[ $arcroleUri ] ) )
				{
					$this->log()->taxonomy_validation( "3.5.2.4.5", "There MUST NOT be more than one arcroleRef element with the same @arcroleURI attribute value",
						array(
							'arcrole' => $arcroleUri,
							'href' => $xml_basename,
						)
					);
				}
			}

			$arcroleRefs[ $arcroleUri ] = $fragment;

			$taxonomy = $this->getTaxonomyForXSD( $arcroleRefHref );
			if ( ! $taxonomy )
			{
				$parts = explode( '#', $arcroleRefHref );
				if ( isset( XBRL_Global::$taxonomiesToIgnore[ $parts[0] ] ) ) continue;
				if ( count( $parts ) == 1 || ! isset( XBRL_Global::$taxonomiesToIgnore[ $parts[0] ] ) )
				{
					$this->log()->taxonomy_validation( "5.1.3.4", "Cannot locate the schema for the arcroleref",
						array(
							'href' => "'$arcroleRefHref'",
							'linkbase' => "'$xml_basename'",
						)
					);
					continue;
				}
			}

			// This role MUST be defined as 'usedOn' in the linkbaseRef for link:calculationArc
			if ( ! count( $taxonomy->arcroleTypes ) || ! isset( $taxonomy->arcroleTypes['link:calculationArc'][ $arcroleUri ] ) )
			{
				$this->log()->taxonomy_validation( "5.1.3.4", "This arcrole is not defined to be used on the calculation linkbase",
					array(
						'arcrole' => "'$arcroleUri'",
						'linkbase' => "'$xml_basename'",
					)
				);
				continue;
			}

			// Make sure this arcrole is in the current taxonomy
			$this->arcroleTypes['link:calculationArc'][ $arcroleUri ] = $taxonomy->arcroleTypes['link:calculationArc'][ $arcroleUri ];
		}

		if ( ! isset( $this->roleTypes[ $usedOn ] ) )
		{
			$this->roleTypes[ $usedOn ] = array();
		}

		$linkbaseRoleRefs = array();

		foreach ( $xml->children( XBRL_Constants::$standardPrefixes[ STANDARD_PREFIX_LINK ] )->roleRef as $roleRefKey => $roleRef )
		{
			$xlinkAttributes = $roleRef->attributes( XBRL_Constants::$standardPrefixes[ STANDARD_PREFIX_XLINK ] );
			$roleRefAttributes = $roleRef->attributes();
			$roleUri = (string) $roleRefAttributes->roleURI;
			$roleRefHref = (string) $xlinkAttributes->href;

			// BMS 2015-04-26 This is neessary now linkbases defined in the schema document are supported
			// because a role reference to a type might be a relative reference to an id in the schema doc.
			$roleRefParts = explode( "#", $roleRefHref );
			if ( ! $roleRefParts )
			{
				$roleRefHref = $this->getTaxonomyXSD();
			}
			else if ( ! $roleRefParts[0] )
			{
				$roleRefParts[0] = $this->getTaxonomyXSD();
				$roleRefHref = implode( "#", $roleRefParts );
			}

			if ( XBRL::isValidating() )
			{
				// BMS 2018-04-26 This test works when the linkbases are in different files not so much when they are all in the schema document
				// if ( isset( $this->linkbaseRoleTypes[ $xml_basename ][ "$usedOn:$roleUri" ] ) )
				if ( isset( $linkbaseRoleRefs[ "$usedOn:$roleUri" ] ) )
				{
					$this->log()->taxonomy_validation( "3.5.2.4.5", "There MUST NOT be more than one roleRef element with the same @roleURI attribute value",
						array(
							'role' => $roleUri,
							'usedon' => $usedOn,
							'href' => $xml_basename,
						)
					);
				}
			}

			$linkbaseRoleRefs[ "$usedOn:$roleUri" ] = $roleRefHref;
			$this->linkbaseRoleTypes[ $xml_basename ][ "$usedOn:$roleUri" ] = $roleRefHref;

			$taxonomy = $this->getTaxonomyForXSD( $roleRefHref );
			if ( ! $taxonomy )
			{
				if ( XBRL::isValidating() )
				{
					$this->log()->taxonomy_validation( "5.1.3.4", "The role taxonomy cannot be located",
						array(
							'role' => $roleUri,
							'href' => $roleRefHref,
						)
					);
				}
				continue;
			}

			$this->context->calculationRoleRefs[ $roleUri ] = array(
				'href' => XBRL::resolve_path( $linkbaseRef['href'], $roleRefHref ),
				'roleUri' => $roleUri,
				'type' => (string) $xlinkAttributes->type,
			);


			if ( ! isset( $taxonomy->roleTypes[ $usedOn ][ $roleUri ] ) )
			{
				$taxonomy->roleTypes[ $usedOn ][ $roleUri ] = array(
					'definition' => "",
					'roleURI' => $roleUri,
					'taxonomy' => $taxonomy->schemaLocation,
					'id' => "",
				);
			}
		}

		if ( count( $this->context->calculationRoleRefs ) === 0 || ! isset( $this->context->calculationRoleRefs[ XBRL_Constants::$defaultLinkRole ] ) )
		{
			$roleUri = XBRL_Constants::$defaultLinkRole;

			$this->context->calculationRoleRefs[ XBRL_Constants::$defaultLinkRole ] = array(
				'type' => 'simple',
				'href' => XBRL::resolve_path( $linkbaseRef['href'], $this->getTaxonomyXSD() ), // $linkbaseRef['href'],
				'roleUri' => $roleUri,
			);

			if ( ! isset( $this->roleTypes[ $usedOn ][ $roleUri ] ) )
			{
				$this->roleTypes[ $usedOn ][ $roleUri ] = array(
					'definition' => "",
					'roleURI' => $roleUri,
					'taxonomy' => $this->schemaLocation,
					'id' => "",
				);
			}
		}

		$standardCalculationRoles = array( XBRL_Constants::$arcRoleSummationItem );

		// Process all the role refs
		foreach ( $this->context->calculationRoleRefs as $roleRefsKey => $calculationRoleRef )
		{
			// Find the calculation link with the same role
			foreach ( $xml->children( XBRL_Constants::$standardPrefixes[ STANDARD_PREFIX_LINK ] )->calculationLink as $linkKey => $calculationLink )
			{
				// Detection of duplicate from/to pairs only applies within an extended link so reset this varaible in each new link
				$this->resetValidateFromToArcPairs();

				$attributes = $calculationLink->attributes( XBRL_Constants::$standardPrefixes[ STANDARD_PREFIX_XLINK ] );
				if ( ! property_exists( $attributes, 'role' ) || (string) $attributes->role != $roleRefsKey )
				{
					continue;
				}

				$this->processNonDimensionalLink(
					$calculationLink,
					XBRL_Constants::$CalculationLinkbaseRef,
					$roleRefsKey,
					$standardCalculationRoles,
					$arcroleRefs,
					$linkbaseRef['href'],
					$xml_basename,
					'calculationArc',
					'Calculation'
				);
			}
		}
	}
678521
private function createLinkbaseRefList()
	{
		$linkbaseBase = (string)$this->xbrlDocument->attributes( XBRL_Constants::$standardPrefixes[ STANDARD_PREFIX_XML ] )->base;

		$nodes = $this->xbrlDocument->children( XBRL_Constants::$standardPrefixes[ STANDARD_PREFIX_SCHEMA ] );
		if ( property_exists( $nodes, 'annotation' ) )
		{
			$annotations = $nodes->annotation;
			foreach( $annotations as $annotation )
			{
				$base = $linkbaseBase;
				$base .= (string)$annotation->attributes( XBRL_Constants::$standardPrefixes[ STANDARD_PREFIX_XML ] )->base;
				if ( property_exists( $annotation, 'appinfo' ) )
				{
					$appInfo = $annotation->appinfo;

					$base .= (string)$appInfo->attributes( XBRL_Constants::$standardPrefixes[ STANDARD_PREFIX_XML ] )->base;
					$linkbaseRefs = $appInfo->children( XBRL_Constants::$standardPrefixes[ STANDARD_PREFIX_LINK ] )->linkbaseRef;

					foreach ( $linkbaseRefs as $linkbaseRefskey => $linkbaseRef )
					{
						$xlinkAttributes = $linkbaseRef->attributes( XBRL_Constants::$standardPrefixes[ STANDARD_PREFIX_XLINK ] );
						$attributes = $linkbaseRef->attributes( XBRL_Constants::$standardPrefixes[ STANDARD_PREFIX_XML ] );

						$role = (string) $xlinkAttributes->role;

						if ( empty( $role ) ) $role = XBRL_Constants::$anyLinkbaseRef;

						$base .= (string) $attributes->base;
						// BMS 2018-04-24 The base should include all the separators is needs
						// if ( ! empty( $base ) && ! XBRL::endsWith( $base, '/' ) )
						// {
						//	$base .= '/';
						// }

						if ( $base )
						{
							$parts = array_filter( explode( "/", $base ), function( $part) { return $part != '.'; } );
							// This pair of instructions removes any existing terminating node
							// such as x/y/z so that only x/y remains.  /x/y/z/ will not be changed
							array_pop( $parts );
							array_push( $parts, "" );
							$base = implode( "/", $parts );
						}

						$linkbaseRef = array(
							'type' => (string) $xlinkAttributes->type,
							'href' => XBRL::resolve_path( $this->schemaLocation, (string) $xlinkAttributes->href ),
							'role' => $role,
							'arcrole' => (string) $xlinkAttributes->arcrole,
							'title' => (string) $xlinkAttributes->title,
							'base' => $base,
						);

						$this->linkbaseTypes[ $role ][] = $linkbaseRef;
					}

					$linkbases = $appInfo->children( XBRL_Constants::$standardPrefixes[ STANDARD_PREFIX_LINK ] )->linkbase;

					foreach ( $linkbases as $linkbaseskey => $linkbase )
					{
						// TODO
					}
				}
			}
		}

	}
809429
private function doRefresh($xmlEntity, array &$visited)
    {
        $oid = spl_object_hash($xmlEntity);
        if (isset($visited[$oid])) {
            return; // Prevent infinite recursion
        }

        $visited[$oid] = $xmlEntity; // mark visited

        $class = $this->xem->getClassMetadata(get_class($xmlEntity));
        if ($this->getXmlEntityState($xmlEntity) == self::STATE_MANAGED) {
            // @todo refresh xml-entity
        } else {
            throw new \InvalidArgumentException("XmlEntity is not MANAGED.");
        }
    }
955509
def _do_element(self, node, initial_other_attrs = [], unused = None):
        ''''''

        # Get state (from the stack) make local copies.
        #   ns_parent -- NS declarations in parent
        #   ns_rendered -- NS nodes rendered by ancestors
        #        ns_local -- NS declarations relevant to this element
        #   xml_attrs -- Attributes in XML namespace from parent
        #       xml_attrs_local -- Local attributes in XML namespace.
        #   ns_unused_inherited -- not rendered namespaces, used for exclusive 
        ns_parent, ns_rendered, xml_attrs = \
                self.state[0], self.state[1].copy(), self.state[2].copy() #0422
                
        ns_unused_inherited = unused
        if unused is None:
            ns_unused_inherited = self.state[3].copy()
            
        ns_local = ns_parent.copy()
        inclusive = _inclusive(self)
        xml_attrs_local = {}

        # Divide attributes into NS, XML, and others.
        other_attrs = []
        in_subset = _in_subset(self.subset, node)
        for a in initial_other_attrs + _attrs(node):
            if a.namespaceURI == XMLNS.BASE:
                n = a.nodeName
                if n == "xmlns:": n = "xmlns"        # DOM bug workaround
                ns_local[n] = a.nodeValue
            elif a.namespaceURI == XMLNS.XML:
                if inclusive or (in_subset and  _in_subset(self.subset, a)): #020925 Test to see if attribute node in subset
                    xml_attrs_local[a.nodeName] = a #0426
            else:
                if  _in_subset(self.subset, a):     #020925 Test to see if attribute node in subset
                    other_attrs.append(a)
                    
#                # TODO: exclusive, might need to define xmlns:prefix here
#                if not inclusive and a.prefix is not None and not ns_rendered.has_key('xmlns:%s' %a.prefix):
#                    ns_local['xmlns:%s' %a.prefix] = ??

            #add local xml:foo attributes to ancestor's xml:foo attributes
            xml_attrs.update(xml_attrs_local)

        # Render the node
        W, name = self.write, None
        if in_subset: 
            name = node.nodeName
            if not inclusive:
                if node.prefix is not None:
                    prefix = 'xmlns:%s' %node.prefix
                else:
                    prefix = 'xmlns'
                    
                if not ns_rendered.has_key(prefix) and not ns_local.has_key(prefix):
                    if not ns_unused_inherited.has_key(prefix):
                        raise RuntimeError,\
                            'For exclusive c14n, unable to map prefix "%s" in %s' %(
                            prefix, node)
                    
                    ns_local[prefix] = ns_unused_inherited[prefix]
                    del ns_unused_inherited[prefix]
                
            W('<')
            W(name)

            # Create list of NS attributes to render.
            ns_to_render = []
            for n,v in ns_local.items():

                # If default namespace is XMLNS.BASE or empty,
                # and if an ancestor was the same
                if n == "xmlns" and v in [ XMLNS.BASE, '' ] \
                and ns_rendered.get('xmlns') in [ XMLNS.BASE, '', None ]:
                    continue

                # "omit namespace node with local name xml, which defines
                # the xml prefix, if its string value is
                # http://www.w3.org/XML/1998/namespace."
                if n in ["xmlns:xml", "xml"] \
                and v in [ 'http://www.w3.org/XML/1998/namespace' ]:
                    continue


                # If not previously rendered
                # and it's inclusive  or utilized
                if (n,v) not in ns_rendered.items():
                    if inclusive or _utilized(n, node, other_attrs, self.unsuppressedPrefixes):
                        ns_to_render.append((n, v))
                    elif not inclusive:
                        ns_unused_inherited[n] = v

            # Sort and render the ns, marking what was rendered.
            ns_to_render.sort(_sorter_ns)
            for n,v in ns_to_render:
                self._do_attr(n, v)
                ns_rendered[n]=v    #0417

            # If exclusive or the parent is in the subset, add the local xml attributes
            # Else, add all local and ancestor xml attributes
            # Sort and render the attributes.
            if not inclusive or _in_subset(self.subset,node.parentNode):  #0426
                other_attrs.extend(xml_attrs_local.values())
            else:
                other_attrs.extend(xml_attrs.values())
            other_attrs.sort(_sorter)
            for a in other_attrs:
                self._do_attr(a.nodeName, a.value)
            W('>')

        # Push state, recurse, pop state.
        state, self.state = self.state, (ns_local, ns_rendered, xml_attrs, ns_unused_inherited)
        for c in _children(node):
            _implementation.handlers[c.nodeType](self, c)
        self.state = state

        if name: W('</%s>' % name)
895135
private function validateXLinkLocatorAttributes( $xlinkAttributes, $linkbaseName, $linkbaseHRef )
	{
		if ( ! XBRL::isValidating() ) return true;

		$result = true;

		if ( ! property_exists( $xlinkAttributes, 'type' ) )
		{
			$this->reportMissingLocatorAttribute( '3.5.3.7.1', 'type', $linkbaseName );
			$result = false;
		}

		if ( ! property_exists( $xlinkAttributes, 'label' ) )
		{
			$this->reportMissingLocatorAttribute( '3.5.3.7.3', 'label', $linkbaseName );
			$result = false;
		}

		if ( ! property_exists( $xlinkAttributes, 'href' ) )
		{
			$this->reportMissingLocatorAttribute( '3.5.3.7.2', 'href', $linkbaseName );
			return false;
		}

		// BMS 2018-04-16 This have been moved to a function called 'validateLocator'
		// $href = (string) $xlinkAttributes->href;
		// $parts = parse_url( $href );
		// if ( ! isset( $parts['path'] ) )
		// {
		// 	if ( ! isset( $parts['fragment'] ) )
		// 	{
		// 		$this->log()->taxonomy_validation( "3.5.3.7.2", "The href of the locator is not valid",
		// 			array(
		// 				'linkbase' => $linkbaseName,
		// 				'href' => $href,
		// 			)
		// 		);
        //
		// 		return false;
		// 	}
        //
		// 	// The locator points to a reference that has already been loaded.  Just check that it has.
		// 	$result = isset( $this->linkbaseIds[ basename( $linkbaseHRef ) ][ trim( $parts['fragment'], '#' ) ] );
		// 	return $result;
		// }
        //
		// if ( XBRL::endsWith( $parts['path'], '.xml' ) )
		// {
		// 	// It's a linkbase reference
		// 	if ( isset( $this->linkbaseIds[ $parts['path'] ] ) )
		// 	{
		// 		return true;
		// 	}
        //
		// 	$linkbaseRef = array(
		// 		'type' => (string) $xlinkAttributes->type,
		// 		// BMS 2017-10-27 This makes the linkbase relative to the location of the schema file which is not correct
		// 		// 'href' => XBRL::resolve_path( $taxonomy->getSchemaLocation(), $href ),
		// 		'href' => XBRL::resolve_path( $this->schemaLocation, $parts['path'] ),
		// 		'role' => XBRL_Constants::$anyLinkbaseRef,
		// 		'arcrole' => \XBRL_Constants::$arcRoleLinkbase,
		// 		'title' => '',
		// 		'base' => '',
		// 	);
        //
		// 	$this->processPresentationLinkbase( $linkbaseRef );
		// 	$this->processLabelLinkbase( $linkbaseRef );
		// 	$this->processDefinitionLinkbase( $linkbaseRef );
		// 	$this->processCalculationLinkbase( $linkbaseRef );
		// 	// Handle custom linkbases
		// 	$this->processCustomLinkbaseArcRoles( $linkbaseRef );
        //
		// 	return true;
		// }
        //
		// /**
		//  * @var XBRL $taxonomy
		//  */
		// $taxonomy = $parts['path'] == $this->getTaxonomyXSD()
		// 	? $this
		// 	: $this->getTaxonomyForXSD( $parts['path'] );
        //
		// if ( ! $taxonomy )
		// {
		// 	// If the linkbase is 'label' look in the labels
		// 	if ( $linkbaseName == 'labels' )
		// 	{
		// 		$labelsHref =& $this->context->labels[ XBRL_Constants::$defaultLinkRole ]['labelshref'];
		// 		if ( ! isset( $labelsHref[ basename( $parts['path'] ) ] ) ||
		// 			 ! isset( $labelsHref[ basename( $parts['path'] ) ][ $parts['fragment'] ] ) )
		// 		{
		// 			$result = false;
		// 		}
		// 	}
		// 	else
		// 	{
		// 		// Look for the taxonomy and include its contents in the DTS
		// 		$xsd = $this->resolve_path( $this->getSchemaLocation(), $href );
		// 		$xsd = strpos( $xsd, '#' ) ? strstr( $xsd, '#', true ) : $xsd;
        //
		// 		$taxonomy = XBRL::withTaxonomy( $xsd );
		// 		// $taxonomy = $this->getTaxonomyForXSD( $xsd );
		// 	}
		// }
        //
		// if ( $taxonomy )
		// {
		// 	// BMS 2018-04-16	This is required by the XBRL 2.1 specification (see test 2012 V-02)
		// 	$element =& $taxonomy->getElementById( $parts['fragment'] );
		// 	if ( ! $element )
		// 	{
		// 		$this->log()->taxonomy_validation( "3.5.3.9.2", "The concept of the locator does not exist in the DTS",
		// 			array(
		// 				'href' => $href,
		// 				'linkbase' => $linkbaseName,
		// 			)
		// 		);
		// 		$result = false;
		// 	}
		// }
		// else
		// {
		// 	$this->log()->taxonomy_validation( "3.5.3.7.2", "The document of the locator does not exist in the DTS",
		// 		array(
		// 			'href' => $href,
		// 			'linkbase' => $linkbaseName,
		// 		)
		// 	);
		// 	$result = false;
		// }

		return $result;
	}
445484
private function validateLinkbase( $domElement )
	{
		$linkbasePath = $domElement->getNodePath();
		$this->localLinkbases[ $linkbasePath ] = array( 'roleRef' => array(), 'arcroleRef' => array() );

		// All the children of $domElement should be extended links
		foreach( $domElement->childNodes as $element => /** @var DOMElement $domLink */ $domLink )
		{
			if ( $domLink->nodeType != XML_ELEMENT_NODE ) continue;

			if ( $domLink->localName == 'roleRef' )
			{
				// Create a hash for the roleRef
				$href = $domLink->getAttributeNodeNS( XBRL_Constants::$standardPrefixes[ STANDARD_PREFIX_XLINK], 'href' );
				$roleUri = $domLink->getAttribute("roleURI");
				$hash = $href->nodeValue . $roleUri;
				if ( in_array( $hash, $this->localLinkbases[ $linkbasePath ]['roleRef'] ) )
				{
					$this->log()->taxonomy_validation( "3.5.2.4.5", "Linkbase roleRef has been duplicated",
						array(
							'element' => $domLink->tagName,
							'href' => $href->nodeValue,
							'roleUri' => $roleUri
						)
					);
				}

				$this->localLinkbases[ $linkbasePath ]['roleRef'][] = $hash;
				continue;
			}

			if ( $domLink->localName == 'arcroleRef' )
			{
				// Create a hash for the roleRef
				$href = $domLink->getAttributeNodeNS( XBRL_Constants::$standardPrefixes[ STANDARD_PREFIX_XLINK], 'href' );
				$arcroleUri = $domLink->getAttribute("arcroleURI");
				$hash = $href->nodeValue . $arcroleUri;
				if ( in_array( $hash, $this->localLinkbases[ $linkbasePath ]['arcroleRef'] ) )
				{
					$this->log()->taxonomy_validation( "linkbase", "Linkbase arcroleRef has been duplicated",
						array(
							'element' => $domLink->tagName,
							'href' => $href->nodeValue,
							'arcroleUri' => $arcroleUri
						)
					);
				}

				$this->localLinkbases[ $linkbasePath ]['arcroleRef'][] = $hash;
				continue;
			}

			// Check the xlink:type is extended
			if ( ! $domLink->hasAttributeNS( XBRL_Constants::$standardPrefixes[ STANDARD_PREFIX_XLINK], 'type' ) )
			{
				$this->log()->taxonomy_validation( "linkbase", "Child elements of a linkbase element should be extended links",
					array(
						'element' => $domLink->tagName
					)
				);

				continue;
			}

			if ( ( $domLinkAttribute = $domLink->getAttributeNS( XBRL_Constants::$standardPrefixes[ STANDARD_PREFIX_XLINK], 'type' ) ) != 'extended' )
			{
				$this->log()->taxonomy_validation( "linkbase", "Child elements of a linkbase element should be extended links",
					array(
						'element' => $domLink->tagName,
						'value' => $domLinkAttribute
					)
				);
			}

			// All the children of $domLink should be locators or resources or arcs
			foreach( $domLink->childNodes as $linkElement => /** @var DOMElement $domLinkElement */ $domLinkElement )
			{
				if ( $domLinkElement->nodeType != XML_ELEMENT_NODE ) continue;

				// Check the xlink:type is extended
				if ( ! $domLinkElement->hasAttributeNS( XBRL_Constants::$standardPrefixes[ STANDARD_PREFIX_XLINK], 'type' ) )
				{
					$this->log()->taxonomy_validation( "linkbase", "Child elements of a link element should have an xlink type attribute",
						array(
							'element' => $domLinkElement->tagName
						)
					);

					continue;
				}

				$domLinkElementAttribute = $domLinkElement->getAttributeNS( XBRL_Constants::$standardPrefixes[ STANDARD_PREFIX_XLINK], 'type' );

				if ( ! in_array( $domLinkElementAttribute, array( 'arc', 'locator', 'resource' ) ) )
				{
					$this->log()->taxonomy_validation( "linkbase", "Child elements of a link element should have an xlink type of 'arc' or 'locator' or 'resource'",
						array(
							'element' => $domLinkElement->tagName,
							'value' => $domLinkElementAttribute
						)
					);
				}
			}
		}
	}
279947
private function arrayToXml(array &$data, SimpleXMLElement $xmlData)
    {
        foreach ($data as $key => $value) {
            $key = ltrim($key, '_');

            if (\is_array($value)) {
                if (\is_numeric($key)) {
                    $key = 'resource';
                }

                if (false === empty($value[JsonTransformer::LINKS_HREF])) {
                    $subnode = $xmlData->addChild('link');
                    $subnode->addAttribute('rel', $key);

                    foreach ($this->linkKeys as $linkKey) {
                        if (!empty($value[$linkKey])) {
                            $subnode->addAttribute($linkKey, $value[$linkKey]);
                        }
                    }
                } else {
                    if (!empty($value[JsonTransformer::LINKS_KEY][JsonTransformer::LINK_SELF][JsonTransformer::LINKS_HREF])) {
                        $subnode = $xmlData->addChild('resource');
                        $subnode->addAttribute(
                            JsonTransformer::LINKS_HREF,
                            $value[JsonTransformer::LINKS_KEY][JsonTransformer::LINK_SELF][JsonTransformer::LINKS_HREF]
                        );

                        if ($key !== 'resource') {
                            $subnode->addAttribute('rel', $key);
                        }
                    } else {
                        $subnode = $xmlData->addChild($key);
                    }
                }

                $this->arrayToXml($value, $subnode);
            } else {
                if ($key !== JsonTransformer::LINKS_HREF) {
                    if ($value === true || $value === false) {
                        $value = ($value) ? 'true' : 'false';
                    }

                    $xmlData->addChild("$key", '<![CDATA['.html_entity_decode($value).']]>');
                }
            }
        }
    }
1224045
def _utilized(n, node, other_attrs, unsuppressedPrefixes):
    ''''''
    if n.startswith('xmlns:'):
        n = n[6:]
    elif n.startswith('xmlns'):
        n = n[5:]
    if (n=="" and node.prefix in ["#default", None]) or \
        n == node.prefix or n in unsuppressedPrefixes: 
            return 1
    for attr in other_attrs:
        if n == attr.prefix: return 1
    # For exclusive need to look at attributes
    if unsuppressedPrefixes is not None:
        for attr in _attrs(node):
            if n == attr.prefix: return 1
            
    return 0
944872
public function moveInto(NodeInterface $referenceNode, string $newName = null): void
    {
        if ($referenceNode === $this || $referenceNode === $this->getParent()) {
            return;
        }

        if ($this->isRoot()) {
            throw new NodeException('The root node cannot be moved.', 1346769001);
        }

        $name = $newName !== null ? $newName : $this->getName();

        if ($referenceNode !== $this->getParent() && $referenceNode->getNode($name) !== null) {
            throw new NodeExistsException(sprintf('Node with path "%s" already exists.', $name), 1292503470);
        }

        if (($referenceNode instanceof Node && !$referenceNode->willChildNodeBeAutoCreated($name)) && !$referenceNode->isNodeTypeAllowedAsChildNode($this->getNodeType())) {
            throw new NodeConstraintException(sprintf('Cannot move %s into %s', $this, $referenceNode), 1404648124);
        }

        $this->emitBeforeNodeMove($this, $referenceNode, NodeDataRepository::POSITION_LAST);
        $this->setPath(NodePaths::addNodePathSegment($referenceNode->getPath(), $name));
        $this->nodeDataRepository->persistEntities();

        $this->nodeDataRepository->setNewIndex($this->nodeData, NodeDataRepository::POSITION_LAST);
        $this->context->getFirstLevelNodeCache()->flush();
        $this->emitAfterNodeMove($this, $referenceNode, NodeDataRepository::POSITION_LAST);
        $this->emitNodeUpdated($this);
    }
208307
public function processCalculationLinkbase( $linkbaseRef )
	{
		// $this->log()->info( "Process definition linkbase {$linkbaseRef[ 'href' ]}" );
		// The 'href' may contain an XPointer fragment that specifies a target in the document
		$parts = explode( '#', $linkbaseRef['href'] );
		$linkbaseRef['href'] = $parts[0];
		$xml_basename = pathinfo( $parts[0], PATHINFO_BASENAME );
		$fragment = isset( $parts[1] ) ? $parts[1] : "";
		$usedOn = 'link:calculationLink';

		// Has it been processed?
		if ( isset( $this->context->processedLinkbases[ "$usedOn:$xml_basename" ] ) )
		{
			return;
		}
		$this->context->processedLinkbases[ "$usedOn:$xml_basename" ] = array( 'linkbase' => $xml_basename, 'usedOn' => $usedOn );

		// If this is an http/https scheme then there should be two forward slashes after the colon.
		// If this is not http/https then there should be just one slash
		$path = XBRL::resolve_path( $linkbaseRef['href'], $linkbaseRef['base'] . $xml_basename );
		// $path = str_replace( "//", "/", pathinfo( $linkbaseRef['href'], PATHINFO_DIRNAME ) . "/" . $linkbaseRef['base'] . "/" . $xml_basename );
		// $path = preg_replace( '~^(https?):/([^/])~', '$1://$2', $path );

		// $path = preg_replace( '~:/([^/])~', '://$1', pathinfo( $linkbaseRef['href'], PATHINFO_DIRNAME ) . "/" . $linkbaseRef['base'] . "/" . $xml_basename );
		// $path = str_replace( "//", "/", pathinfo( $linkbaseRef['href'], PATHINFO_DIRNAME ) . "/" . $linkbaseRef['base'] . $xml_basename );

		$xml = XBRL::getXml( $path, $this->context );
		if ( $xml === null )
		{
			return $this->reportMissingLinkbaseFile( $linkbaseRef );
		}

		if ( $fragment )
		{
			// TODO Validate the XPointer fragment and set the $xml variable to the location defined by the fragment
			if ( $this->isPointer( $fragment, $xml, null, $name, $domNode ) )
			{
				if ( $domNode )
				{
					$xml = simplexml_import_dom( $domNode );
					unset( $domNode );
				}
			}
		}

		$this->processCalculationLinkbaseXml( $linkbaseRef, $xml, $xml_basename, $usedOn );
	}
1058102
private function validateXLinkArcAttributes( $xlinkAttributes, $linkbase )
	{
		if ( ! XBRL::isValidating() ) return true;

		$result = true;

		if ( ! property_exists( $xlinkAttributes, 'arcrole' ) )
		{
			$this->reportMissingArcAttribute( '3.5.3.9.4', 'arcrole', $linkbase );
			$result = false;
		}

		if ( ! property_exists( $xlinkAttributes, 'to' ) )
		{
			$this->reportMissingArcAttribute( '3.5.3.9.3', 'to', $linkbase );
			$result = false;
		}

		if ( ! property_exists( $xlinkAttributes, 'from' ) )
		{
			$this->reportMissingArcAttribute( '3.5.3.9.2', 'from', $linkbase );
			$result = false;
		}

		return true;
	}
1239018
static function processNodeTransformationChildren( $useComments, $php, $tpl, &$node, &$children, &$resourceData )
    {
        if ( $children )
        {
            $newChildren = array();
            foreach ( $children as $childNode )
            {
                $newChildNode = eZTemplateCompiler::processNodeTransformationChild( $useComments, $php, $tpl, $childNode, $resourceData );
                if ( !$newChildNode )
                    $newChildren[] = $childNode;
                else
                    $newChildren = array_merge( $newChildren, $newChildNode );
            }
            if ( count( $newChildren ) > 0 )
                return $newChildren;
        }
        return $children;
    }
713345
public static function checkString($xml, $filename = '')
    {
        $doc = Utilities::stringToDOMDocument($xml, $filename);
        $errors = null;
        $preUseInternalErrors = libxml_use_internal_errors(true);
        try {
            if (!$doc->schemaValidateSource(static::getSchema())) {
                $errors = Utilities::explainLibXmlErrors($filename);
            }
        } catch (Exception $x) {
            libxml_use_internal_errors($preUseInternalErrors);
            libxml_clear_errors();
            throw $x;
        }
        libxml_use_internal_errors($preUseInternalErrors);

        return $errors;
    }
1014868
private function validateXLinkArcrole( $linkbase, $value )
	{
		if ( ! XBRL::isValidating() ) return true;

		if ( $value == XBRL_Constants::$arcRoleConceptLabel ) return true;

		return $this->reportXLinkArcTypeError( "3.5.3.9.4", $linkbase, $value );
	}
1308927
protected function processLinkNode($xmlArray)
    {
        $link = [];
        $linkValue = $xmlArray[Resources::LINK];

        if (is_array($linkValue)) {
            /** @var SimpleXMLElement $linkValueInstance */
            foreach ($xmlArray[Resources::LINK] as $linkValueInstance) {
                $linkInstance = new AtomLink();
                $linkInstance->parseXml($linkValueInstance->asXML());
                $link[] = $linkInstance;
            }
        } else {
            $linkInstance = new AtomLink();
            $linkInstance->parseXml($linkValue->asXML());
            $link[] = $linkInstance;
        }

        return $link;
    }
49476
public void xmlWriteOn(FormattedWriter writer) throws IOException {
        String name = "link";
        writer.write("<");
        writer.write(name);
        xmlWriteAttributesOn(writer);
        writer.write(" />");
    }
863157
static function processElementTransformationList( $tpl, &$node, $elements, &$privateData )
    {
        $useComments = $privateData['use-comments'];
        $php =& $privateData['php-creator'];
        $resourceData =& $privateData['resource-data'];
        $elementTree = $elements;
        $newElements = eZTemplateCompiler::processElementTransformationChild( $useComments, $php, $tpl, $node,
                                                                              $elementTree, $elements, $resourceData );
        if ( $newElements )
            return $newElements;
        return $elements;
    }