1010use GoetasWebservices \XML \XSDReader \Schema \Element \ElementDef ;
1111use GoetasWebservices \XML \XSDReader \Schema \Element \ElementItem ;
1212use GoetasWebservices \XML \XSDReader \Schema \Element \ElementRef ;
13+ use GoetasWebservices \XML \XSDReader \Schema \Element \ElementSingle ;
1314use GoetasWebservices \XML \XSDReader \Schema \Item ;
1415use GoetasWebservices \XML \XSDReader \Schema \Schema ;
1516use GoetasWebservices \XML \XSDReader \Schema \SchemaItem ;
@@ -157,7 +158,7 @@ public function &visitElementDef(Schema $schema, ElementDef $element)
157158 $ data ["xml_root_namespace " ] = $ schema ->getTargetNamespace ();
158159
159160 if (!$ schema ->getElementsQualification () && !($ element instanceof Element && $ element ->isQualified ())) {
160- $ data ["xml_root_name " ] = "ns- " . substr (sha1 ($ data ["xml_root_namespace " ]), 0 , 8 ) . ": " . $ data [ " xml_root_name " ] ;
161+ $ data ["xml_root_name " ] = "ns- " . substr (sha1 ($ data ["xml_root_namespace " ]), 0 , 8 ) . ": " . $ element -> getName () ;
161162 }
162163 }
163164 $ this ->classes [spl_object_hash ($ element )]["class " ] = &$ class ;
@@ -428,6 +429,21 @@ protected function typeHasValue(Type $type, $parentClass, $name)
428429 return false ;
429430 }
430431
432+ /**
433+ * @param Schema $schema
434+ * @param Element|ElementSingle $element
435+ * @return string|null
436+ */
437+ protected function getElementNamespace (Schema $ schema , ElementItem $ element )
438+ {
439+ if ($ element ->getSchema ()->getTargetNamespace () &&
440+ ($ schema ->getElementsQualification () || ($ element instanceof Element && $ element ->isQualified ()) || !$ element ->isLocal ())
441+ ) {
442+ return $ element ->getSchema ()->getTargetNamespace ();
443+ }
444+ return null ;
445+ }
446+
431447 /**
432448 *
433449 * @param PHPClass $class
@@ -446,8 +462,9 @@ protected function &visitElement(&$class, Schema $schema, ElementItem $element,
446462 if (!$ this ->useCdata ) {
447463 $ property ["xml_element " ]["cdata " ] = $ this ->useCdata ;
448464 }
449- if ($ element ->getSchema ()->getTargetNamespace () && ($ schema ->getElementsQualification () || ($ element instanceof Element && $ element ->isQualified ()))) {
450- $ property ["xml_element " ]["namespace " ] = $ element ->getSchema ()->getTargetNamespace ();
465+ $ elementNamespace = $ this ->getElementNamespace ($ schema , $ element );
466+ if ($ elementNamespace ) {
467+ $ property ["xml_element " ]["namespace " ] = $ elementNamespace ;
451468 }
452469
453470 $ property ["accessor " ]["getter " ] = "get " . Inflector::classify ($ this ->getNamingStrategy ()->getPropertyName ($ element ));
@@ -477,8 +494,9 @@ protected function &visitElement(&$class, Schema $schema, ElementItem $element,
477494 $ property ["xml_list " ]["entry_name " ] = $ itemOfArray ->getName ();
478495 $ property ["xml_list " ]["skip_when_empty " ] = ($ element ->getMin () === 0 );
479496
480- if ($ itemOfArray ->getSchema ()->getTargetNamespace () && ($ itemOfArray ->getSchema ()->getElementsQualification ())) {
481- $ property ["xml_list " ]["namespace " ] = $ itemOfArray ->getSchema ()->getTargetNamespace ();
497+ $ elementNamespace = $ this ->getElementNamespace ($ schema , $ itemOfArray );
498+ if ($ elementNamespace ) {
499+ $ property ["xml_list " ]["namespace " ] = $ elementNamespace ;
482500 }
483501 return $ property ;
484502 } elseif ($ itemOfArray = $ this ->isArrayType ($ t )) {
@@ -500,15 +518,19 @@ protected function &visitElement(&$class, Schema $schema, ElementItem $element,
500518 $ property ["type " ] = "GoetasWebservices\Xsd\XsdToPhp\Jms\SimpleListOf< " . key ($ visitedType ) . "> " ;
501519 }
502520
503- if ($ schema ->getTargetNamespace () && ($ schema ->getElementsQualification () || ($ element instanceof Element && $ element ->isQualified ()))) {
504- $ property ["xml_list " ]["namespace " ] = $ schema ->getTargetNamespace ();
521+ $ elementNamespace = $ this ->getElementNamespace ($ schema , $ element );
522+
523+ if ($ elementNamespace != null ) {
524+ $ property ["xml_list " ]["namespace " ] = $ elementNamespace ;
505525 }
506526 return $ property ;
507527 } elseif ($ this ->isArrayElement ($ element )) {
508528 $ property ["xml_list " ]["inline " ] = true ;
509529 $ property ["xml_list " ]["entry_name " ] = $ element ->getName ();
510- if ($ schema ->getTargetNamespace () && ($ schema ->getElementsQualification () || ($ element instanceof Element && $ element ->isQualified ()))) {
511- $ property ["xml_list " ]["namespace " ] = $ schema ->getTargetNamespace ();
530+
531+ $ elementNamespace = $ this ->getElementNamespace ($ schema , $ element );
532+ if ($ elementNamespace != null ) {
533+ $ property ["xml_list " ]["namespace " ] = $ elementNamespace ;
512534 }
513535
514536 $ property ["type " ] = "array< " . $ this ->findPHPClass ($ class , $ element ) . "> " ;
0 commit comments