Example #1
0
void xml_file_write(xml_data_node *node, mame_file *file)
{
	/* ensure this is a root node */
	assert_always(node->name == NULL, "xml_file_write called with a non-root node");

	/* output a simple header */
	mame_fprintf(file, "<?xml version=\"1.0\"?>\n");
	mame_fprintf(file, "<!-- This file is autogenerated; comments and unknown tags will be stripped -->\n");

	/* loop over children of the root and output */
	for (node = node->child; node; node = node->next)
		write_node_recursive(node, 0, file);
}
Example #2
0
void xml_file_write(xml_data_node *node, util::core_file &file)
{
	/* ensure this is a root node */
	if (node->name != nullptr)
		return;

	/* output a simple header */
	file.printf("<?xml version=\"1.0\"?>\n");
	file.printf("<!-- This file is autogenerated; comments and unknown tags will be stripped -->\n");

	/* loop over children of the root and output */
	for (node = node->child; node; node = node->next)
		write_node_recursive(node, 0, file);
}
Example #3
0
static void write_node_recursive(xml_data_node *node, int indent, util::core_file &file)
{
	xml_attribute_node *anode;
	xml_data_node *child;

	/* output this tag */
	file.printf("%*s<%s", indent, "", node->name);

	/* output any attributes */
	for (anode = node->attribute; anode; anode = anode->next)
		file.printf(" %s=\"%s\"", anode->name, anode->value);

	/* if there are no children and no value, end the tag here */
	if (node->child == nullptr && node->value == nullptr)
		file.printf(" />\n");

	/* otherwise, close this tag and output more stuff */
	else
	{
		file.printf(">\n");

		/* if there is a value, output that here */
		if (node->value != nullptr)
			file.printf("%*s%s\n", indent + 4, "", node->value);

		/* loop over children and output them as well */
		if (node->child != nullptr)
		{
			for (child = node->child; child; child = child->next)
				write_node_recursive(child, indent + 4, file);
		}

		/* write a closing tag */
		file.printf("%*s</%s>\n", indent, "", node->name);
	}
}