diff Lib/IMPL/DOM/Node.pm @ 152:1e7f03414b65

DOM: schema improvements DOM: saving to XML::Writer feature
author wizard
date Thu, 23 Sep 2010 03:58:43 +0400
parents e6447ad85cb4
children 76515373dac0
line wrap: on
line diff
--- a/Lib/IMPL/DOM/Node.pm	Fri Aug 20 16:33:37 2010 +0400
+++ b/Lib/IMPL/DOM/Node.pm	Thu Sep 23 03:58:43 2010 +0400
@@ -317,7 +317,7 @@
 }
 
 sub _getIsComplex {
-    $_[0]->childNodes->Count ? 1 : 0;
+    ($_[0]->{$childNodes} and $_[0]->{$childNodes}->Count) ? 1 : 0;
 }
 
 sub _updateDocRefs {
@@ -392,6 +392,33 @@
 	return (keys %props,keys %{$this->{$_propertyMap}});
 }
 
+sub save {
+	my ($this,$writer) = @_;
+	
+	if ( not ( $this->isComplex or defined $this->{$nodeValue} ) ) {
+		$writer->emptyTag(
+			$this->{$nodeName},
+			map {
+				$_,
+				$this->nodeProperty($_)
+			} grep defined $this->nodeProperty($_), $this->listProperties
+		);
+	} else {
+		$writer->startTag(
+			$this->{$nodeName},
+			map {
+				$_,
+				$this->nodeProperty($_)
+			} grep defined $this->nodeProperty($_), $this->listProperties
+		);
+		$writer->characters($this->{$nodeValue}) if $this->{$nodeValue};
+		
+		$_->save($writer) foreach $this->childNodes;
+		
+		$writer->endTag($this->{$nodeName});
+	}
+}
+
 sub qname {
     $_[0]->{$nodeName};
 }