mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Added handy new function parseXMLIfTagMatches(), and refactored a lot of old code that was parsing XML in a more clunky way
This commit is contained in:
parent
3b36c3e198
commit
0fb8c8e82a
20 changed files with 130 additions and 148 deletions
|
|
@ -186,35 +186,20 @@ bool PropertiesFile::save()
|
|||
|
||||
bool PropertiesFile::loadAsXml()
|
||||
{
|
||||
XmlDocument parser (file);
|
||||
|
||||
if (auto doc = parser.getDocumentElement (true))
|
||||
if (auto doc = parseXMLIfTagMatches (file, PropertyFileConstants::fileTag))
|
||||
{
|
||||
if (doc->hasTagName (PropertyFileConstants::fileTag))
|
||||
forEachXmlChildElementWithTagName (*doc, e, PropertyFileConstants::valueTag)
|
||||
{
|
||||
doc = parser.getDocumentElement();
|
||||
auto name = e->getStringAttribute (PropertyFileConstants::nameAttribute);
|
||||
|
||||
if (doc != nullptr)
|
||||
{
|
||||
forEachXmlChildElementWithTagName (*doc, e, PropertyFileConstants::valueTag)
|
||||
{
|
||||
auto name = e->getStringAttribute (PropertyFileConstants::nameAttribute);
|
||||
|
||||
if (name.isNotEmpty())
|
||||
getAllProperties().set (name,
|
||||
e->getFirstChildElement() != nullptr
|
||||
? e->getFirstChildElement()->toString (XmlElement::TextFormat().singleLine().withoutHeader())
|
||||
: e->getStringAttribute (PropertyFileConstants::valueAttribute));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// must be a pretty broken XML file we're trying to parse here,
|
||||
// or a sign that this object needs an InterProcessLock,
|
||||
// or just a failure reading the file. This last reason is why
|
||||
// we don't jassertfalse here.
|
||||
if (name.isNotEmpty())
|
||||
getAllProperties().set (name,
|
||||
e->getFirstChildElement() != nullptr
|
||||
? e->getFirstChildElement()->toString (XmlElement::TextFormat().singleLine().withoutHeader())
|
||||
: e->getStringAttribute (PropertyFileConstants::valueAttribute));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
@ -231,7 +216,7 @@ bool PropertiesFile::saveAsXml()
|
|||
e->setAttribute (PropertyFileConstants::nameAttribute, props.getAllKeys() [i]);
|
||||
|
||||
// if the value seems to contain xml, store it as such..
|
||||
if (auto childElement = XmlDocument::parse (props.getAllValues() [i]))
|
||||
if (auto childElement = parseXML (props.getAllValues() [i]))
|
||||
e->addChildElement (childElement.release());
|
||||
else
|
||||
e->setAttribute (PropertyFileConstants::valueAttribute, props.getAllValues() [i]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue