diff options
| author | arseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640> | 2010-05-21 05:50:53 +0000 | 
|---|---|---|
| committer | arseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640> | 2010-05-21 05:50:53 +0000 | 
| commit | 7c01cf8df31ed0636d12d907d32cfc3cfbc452ea (patch) | |
| tree | 2ef7d0d9377b76ba65fba8ef67a1d7b2a212c267 /src | |
| parent | e31d977c8096fd9566bda50d16e843042fe36a50 (diff) | |
Nodes/attributes with empty names now are printed as :anonymous
git-svn-id: http://pugixml.googlecode.com/svn/trunk@441 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'src')
| -rw-r--r-- | src/pugixml.cpp | 67 | 
1 files changed, 32 insertions, 35 deletions
diff --git a/src/pugixml.cpp b/src/pugixml.cpp index 75db295..60e0b2f 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -2705,8 +2705,26 @@ namespace  		}
  	}
 +	void node_output_attributes(xml_buffered_writer& writer, const xml_node& node)
 +	{
 +		const char_t* default_name = PUGIXML_TEXT(":anonymous");
 +
 +		for (xml_attribute a = node.first_attribute(); a; a = a.next_attribute())
 +		{
 +			writer.write(' ');
 +			writer.write(a.name()[0] ? a.name() : default_name);
 +			writer.write('=', '"');
 +
 +			text_output_escaped(writer, a.value(), oct_special_attr);
 +
 +			writer.write('"');
 +		}
 +	}
 +
  	void node_output(xml_buffered_writer& writer, const xml_node& node, const char_t* indent, unsigned int flags, unsigned int depth)
  	{
 +		const char_t* default_name = PUGIXML_TEXT(":anonymous");
 +
  		if ((flags & format_indent) != 0 && (flags & format_raw) == 0)
  			for (unsigned int i = 0; i < depth; ++i) writer.write(indent);
 @@ -2721,19 +2739,12 @@ namespace  		case node_element:
  		{
 -			writer.write('<');
 -			writer.write(node.name());
 -
 -			for (xml_attribute a = node.first_attribute(); a; a = a.next_attribute())
 -			{
 -				writer.write(' ');
 -				writer.write(a.name());
 -				writer.write('=', '"');
 +			const char_t* name = node.name()[0] ? node.name() : default_name;
 -				text_output_escaped(writer, a.value(), oct_special_attr);
 +			writer.write('<');
 +			writer.write(name);
 -				writer.write('"');
 -			}
 +			node_output_attributes(writer, node);
  			if (flags & format_raw)
  			{
 @@ -2747,7 +2758,7 @@ namespace  						node_output(writer, n, indent, flags, depth + 1);
  					writer.write('<', '/');
 -					writer.write(node.name());
 +					writer.write(name);
  					writer.write('>');
  				}
  			}
 @@ -2760,7 +2771,7 @@ namespace  				text_output_escaped(writer, node.first_child().value(), oct_special_pcdata);
  				writer.write('<', '/');
 -				writer.write(node.name());
 +				writer.write(name);
  				writer.write('>', '\n');
  			}
  			else
 @@ -2774,7 +2785,7 @@ namespace  					for (unsigned int i = 0; i < depth; ++i) writer.write(indent);
  				writer.write('<', '/');
 -				writer.write(node.name());
 +				writer.write(name);
  				writer.write('>', '\n');
  			}
 @@ -2802,37 +2813,23 @@ namespace  			break;
  		case node_pi:
 -			writer.write('<', '?');
 -			writer.write(node.name());
 -			if (node.value()[0])
 -			{
 -				writer.write(' ');
 -				writer.write(node.value());
 -			}
 -			writer.write('?', '>');
 -			if ((flags & format_raw) == 0) writer.write('\n');
 -			break;
 -		
  		case node_declaration:
 -		{
  			writer.write('<', '?');
 -			writer.write(node.name());
 +			writer.write(node.name()[0] ? node.name() : default_name);
 -			for (xml_attribute a = node.first_attribute(); a; a = a.next_attribute())
 +			if (node.type() == node_declaration)
 +			{
 +				node_output_attributes(writer, node);
 +			}
 +			else if (node.value()[0])
  			{
  				writer.write(' ');
 -				writer.write(a.name());
 -				writer.write('=', '"');
 -
 -				text_output_escaped(writer, a.value(), oct_special_attr);
 -
 -				writer.write('"');
 +				writer.write(node.value());
  			}
  			writer.write('?', '>');
  			if ((flags & format_raw) == 0) writer.write('\n');
  			break;
 -		}
  		default:
  			assert(false);
  | 
