⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 class.xmlschema.php

📁 学校网站源码http://您的网址/admin/admin_login.asp 默认登录用户:admin 默认登录密码:admin
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php


class xmlschema extends nusoap_base
{

	var $schema = "";
	var $xml = "";
	var $enclosingNamespaces;
	var $schemaInfo = array( );
	var $schemaTargetNamespace = "";
	var $attributes = array( );
	var $complexTypes = array( );
	var $currentComplexType = false;
	var $elements = array( );
	var $currentElement = false;
	var $simpleTypes = array( );
	var $currentSimpleType = false;
	var $imports = array( );
	var $parser;
	var $position = 0;
	var $depth = 0;
	var $depth_array = array( );
	var $message = array( );
	var $defaultNamespace = array( );

	function xmlschema( $schema = "", $xml = "", $namespaces = array( ) )
	{
		$this->debug( "xmlschema class instantiated, inside constructor" );
		$this->schema = $schema;
		$this->xml = $xml;
		$this->enclosingNamespaces = $namespaces;
		$this->namespaces = array_merge( $this->namespaces, $namespaces );
		if ( $schema != "" )
		{
			$this->debug( "initial schema file: ".$schema );
			$this->parsefile( $schema, "schema" );
		}
		if ( $xml != "" )
		{
			$this->debug( "initial xml file: ".$xml );
			$this->parsefile( $xml, "xml" );
		}
	}

	function parsefile( $xml, $type )
	{
		if ( $xml != "" )
		{
			$xmlStr = @join( "", @file( $xml ) );
			if ( $xmlStr == "" )
			{
				$msg = "Error reading XML from ".$xml;
				$this->seterror( $msg );
				$this->debug( $msg );
				return false;
			}
			else
			{
				$this->debug( "parsing {$xml}" );
				$this->parsestring( $xmlStr, $type );
				$this->debug( "done parsing {$xml}" );
				return true;
			}
		}
		return false;
	}

	function parsestring( $xml, $type )
	{
		if ( $xml != "" )
		{
			$this->parser = xml_parser_create( );
			xml_parser_set_option( $this->parser, XML_OPTION_CASE_FOLDING, 0 );
			xml_set_object( $this->parser, $this );
			if ( $type == "schema" )
			{
				xml_set_element_handler( $this->parser, "schemaStartElement", "schemaEndElement" );
				xml_set_character_data_handler( $this->parser, "schemaCharacterData" );
			}
			else if ( $type == "xml" )
			{
				xml_set_element_handler( $this->parser, "xmlStartElement", "xmlEndElement" );
				xml_set_character_data_handler( $this->parser, "xmlCharacterData" );
			}
			if ( !xml_parse( $this->parser, $xml, true ) )
			{
				$errstr = sprintf( "XML error parsing XML schema on line %d: %s", xml_get_current_line_number( $this->parser ), xml_error_string( xml_get_error_code( $this->parser ) ) );
				$this->debug( $errstr );
				$this->debug( "XML payload:\n".$xml );
				$this->seterror( $errstr );
			}
			xml_parser_free( $this->parser );
		}
		else
		{
			$this->debug( "no xml passed to parseString()!!" );
			$this->seterror( "no xml passed to parseString()!!" );
		}
	}

	function schemastartelement( $parser, $name, $attrs )
	{
		$pos = $this->position++;
		$depth = $this->depth++;
		$this->depth_array[$depth] = $pos;
		$this->message[$pos] = array( "cdata" => "" );
		if ( 0 < $depth )
		{
			$this->defaultNamespace[$pos] = $this->defaultNamespace[$this->depth_array[$depth - 1]];
		}
		else
		{
			$this->defaultNamespace[$pos] = false;
		}
		if ( $prefix = $this->getprefix( $name ) )
		{
			$name = $this->getlocalpart( $name );
		}
		else
		{
			$prefix = "";
		}
		if ( 0 < count( $attrs ) )
		{
			foreach ( $attrs as $k => $v )
			{
				if ( ereg( "^xmlns", $k ) )
				{
					if ( $ns_prefix = substr( strrchr( $k, ":" ), 1 ) )
					{
						$this->namespaces[$ns_prefix] = $v;
					}
					else
					{
						$this->defaultNamespace[$pos] = $v;
						if ( !$this->getprefixfromnamespace( $v ) )
						{
							$this->namespaces["ns".( count( $this->namespaces ) + 1 )] = $v;
						}
					}
					if ( $v == "http://www.w3.org/2001/XMLSchema" || $v == "http://www.w3.org/1999/XMLSchema" )
					{
						$this->XMLSchemaVersion = $v;
						$this->namespaces['xsi'] = $v."-instance";
					}
				}
			}
			foreach ( $attrs as $k => $v )
			{
				$k = strpos( $k, ":" ) ? $this->expandqname( $k ) : $k;
				$v = strpos( $v, ":" ) ? $this->expandqname( $v ) : $v;
				$eAttrs[$k] = $v;
			}
			$attrs = $eAttrs;
		}
		else
		{
			$attrs = array( );
		}
		switch ( $name )
		{
		case "all" :
		case "choice" :
		case "sequence" :
			$this->complexTypes[$this->currentComplexType]['compositor'] = $name;
			if ( $name == "all" || $name == "sequence" )
			{
				$this->complexTypes[$this->currentComplexType]['phpType'] = "struct";
			}
			break;
		case "attribute" :
			$this->xdebug( "parsing attribute ".$this->vardump( $attrs ) );
			if ( isset( $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'] ) )
			{
				$v = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
				if ( !strpos( $v, ":" ) )
				{
					if ( $this->defaultNamespace[$pos] )
					{
						$attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'] = $this->defaultNamespace[$pos].":".$attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
					}
				}
			}
			if ( isset( $attrs['name'] ) )
			{
				$this->attributes[$attrs['name']] = $attrs;
				$aname = $attrs['name'];
			}
			else if ( isset( $attrs['ref'] ) && $attrs['ref'] == "http://schemas.xmlsoap.org/soap/encoding/:arrayType" )
			{
				if ( isset( $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'] ) )
				{
					$aname = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
				}
				else
				{
					$aname = "";
				}
			}
			else if ( isset( $attrs['ref'] ) )
			{
				$aname = $attrs['ref'];
				$this->attributes[$attrs['ref']] = $attrs;
			}
			if ( isset( $this->currentComplexType ) )
			{
				$this->complexTypes[$this->currentComplexType]['attrs'][$aname] = $attrs;
			}
			else if ( isset( $this->currentElement ) )
			{
				$this->elements[$this->currentElement]['attrs'][$aname] = $attrs;
			}
			if ( isset( $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'] ) || $this->getlocalpart( $aname ) == "arrayType" )
			{
				$this->complexTypes[$this->currentComplexType]['phpType'] = "array";
				$prefix = $this->getprefix( $aname );
				if ( isset( $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'] ) )
				{
					$v = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
				}
				else
				{
					$v = "";
				}
				if ( strpos( $v, "[,]" ) )
				{
					$this->complexTypes[$this->currentComplexType]['multidimensional'] = true;
				}
				$v = substr( $v, 0, strpos( $v, "[" ) );
				if ( !strpos( $v, ":" ) && isset( $this->typemap[$this->XMLSchemaVersion][$v] ) )
				{
					$v = $this->XMLSchemaVersion.":".$v;
				}
				$this->complexTypes[$this->currentComplexType]['arrayType'] = $v;
			}
			break;
		case "complexType" :
			if ( isset( $attrs['name'] ) )
			{
				$this->xdebug( "processing named complexType ".$attrs['name'] );
				$this->currentElement = false;
				$this->currentComplexType = $attrs['name'];
				$this->complexTypes[$this->currentComplexType] = $attrs;
				$this->complexTypes[$this->currentComplexType]['typeClass'] = "complexType";
				if ( isset( $attrs['base'] ) && ereg( ":Array\$", $attrs['base'] ) )
				{
					$this->complexTypes[$this->currentComplexType]['phpType'] = "array";
				}
				else
				{
					$this->complexTypes[$this->currentComplexType]['phpType'] = "struct";
				}
			}
			else
			{
				$this->xdebug( "processing unnamed complexType for element ".$this->currentElement );
				$this->currentComplexType = $this->currentElement."_ContainedType";
				$this->currentElement = false;
				$this->complexTypes[$this->currentComplexType] = $attrs;
				$this->complexTypes[$this->currentComplexType]['typeClass'] = "complexType";
				if ( isset( $attrs['base'] ) && ereg( ":Array\$", $attrs['base'] ) )
				{
					$this->complexTypes[$this->currentComplexType]['phpType'] = "array";
				}
				else
				{
					$this->complexTypes[$this->currentComplexType]['phpType'] = "struct";
				}
			}
			break;
		case "element" :
			if ( isset( $attrs['type'] ) )
			{
				$this->xdebug( "processing typed element ".$attrs['name']." of type ".$attrs['type'] );
				$this->currentElement = $attrs['name'];
				$this->elements[$attrs['name']] = $attrs;
				$this->elements[$attrs['name']]['typeClass'] = "element";
				if ( !isset( $this->elements[$attrs['name']]['form'] ) )
				{
					$this->elements[$attrs['name']]['form'] = $this->schemaInfo['elementFormDefault'];
				}
				$ename = $attrs['name'];
			}
			else if ( isset( $attrs['ref'] ) )
			{
				$ename = $attrs['ref'];
			}
			else
			{
				$this->xdebug( "processing untyped element ".$attrs['name'] );
				$this->currentElement = $attrs['name'];
				$this->elements[$attrs['name']] = $attrs;
				$this->elements[$attrs['name']]['typeClass'] = "element";
				$this->elements[$attrs['name']]['type'] = $this->schemaTargetNamespace.":".$attrs['name']."_ContainedType";
				if ( !isset( $this->elements[$attrs['name']]['form'] ) )
				{
					$this->elements[$attrs['name']]['form'] = $this->schemaInfo['elementFormDefault'];
				}
			}
			if ( isset( $ename ) && $this->currentComplexType )
			{
				$this->complexTypes[$this->currentComplexType]['elements'][$ename] = $attrs;
			}
			break;
		case "import" :
			if ( isset( $attrs['schemaLocation'] ) )
			{
				$this->imports[$attrs['namespace']][] = array(
					"location" => $attrs['schemaLocation'],
					"loaded" => false
				);
			}
			else
			{
				$this->imports[$attrs['namespace']][] = array(
					"location" => "",
					"loaded" => true
				);
				if ( !$this->getprefixfromnamespace( $attrs['namespace'] ) )
				{
					$this->namespaces["ns".( count( $this->namespaces ) + 1 )] = $attrs['namespace'];
				}
			}
			break;
		case "restriction" :
			if ( $this->currentElement )
			{
				$this->elements[$this->currentElement]['type'] = $attrs['base'];
			}
			else if ( $this->currentSimpleType )
			{
				$this->simpleTypes[$this->currentSimpleType]['type'] = $attrs['base'];
			}
			else if ( $this->currentComplexType )
			{
				$this->complexTypes[$this->currentComplexType]['restrictionBase'] = $attrs['base'];
				if ( strstr( $attrs['base'], ":" ) == ":Array" )
				{
					$this->complexTypes[$this->currentComplexType]['phpType'] = "array";
				}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -