Пример #1
0
	Node * Node::FindEditChildByAttrib (	std::string const & childName, 
											std::string const & attrName, 
											std::string const & attrValue)
	{
		XML::Node::ChildIter it = FirstChild ();
		XML::Node::ChildIter last = LastChild ();
		while (it != last)
		{
			XML::Node * child = *it;
			if (child->GetName () == childName && child->FindAttribValue (attrName) == attrValue)
				return child;
			++it;
		}
		return 0;
	}
Пример #2
0
	void Node::Write (std::ostream & out, unsigned indent) const
	{
		WriteOpeningTag (out, indent);
		if (!_closed)
		{
			for (ConstChildIter it = FirstChild (); it != LastChild (); ++it)
			{
				XML::Node * child = *it;
				if (child->GetName ().empty ()) // text
				{
					out << Indentation (indent) << child->GetAttribValue ("Text") << std::endl;
				}
				else
				{
					child->Write (out, indent + 2);
				}
			}
		}
		WriteClosingTag (out, indent);
	}
Bool BonkEnc::CDDBBatch::ReadEntries()
{
	String	 inputFormat = String::SetInputFormat("UTF-8");
	String	 outputFormat = String::SetOutputFormat("UTF-8");

	// Read saved queries from XML

	XML::Document	*document = new XML::Document();

	if (document->LoadFile(String(config->configDir).Append("cddb\\queries.xml")) == Success())
	{
		XML::Node	*root = document->GetRootNode();

		if (root != NIL)
		{
			for (Int i = 0; i < root->GetNOfNodes(); i++)
			{
				XML::Node	*node = root->GetNthNode(i);

				if (node->GetName() == "query") queries.Add(node->GetContent());
			}
		}
	}

	delete document;

	// Read saved submits from XML and database cache

	document = new XML::Document();

	if (document->LoadFile(String(config->configDir).Append("cddb\\submits.xml")) == Success())
	{
		XML::Node	*root = document->GetRootNode();

		if (root != NIL)
		{
			for (Int i = 0; i < root->GetNOfNodes(); i++)
			{
				XML::Node	*node = root->GetNthNode(i);

				if (node->GetName() == "submit")
				{
					InStream	*in = new InStream(STREAM_FILE, String(config->configDir).Append("cddb\\").Append(node->GetAttributeByName("category")->GetContent()).Append("\\").Append(node->GetContent()), IS_READONLY);

					if (in->Size() > 0)
					{
						String	 result = in->InputString(in->Size());
						CDDBInfo cddbInfo;

						ParseCDDBRecord(result, cddbInfo);

						cddbInfo.category = node->GetAttributeByName("category")->GetContent();

						for (Int i = 0; i < submits.Length(); i++)
						{
							if (submits.GetNth(i) == cddbInfo)
							{
								submits.Remove(submits.GetNthIndex(i));

								break;
							}
						}

						submits.Add(cddbInfo);
					}

					delete in;
				}
			}
		}
	}

	delete document;

	String::SetInputFormat(inputFormat);
	String::SetOutputFormat(outputFormat);

	return True;
}