Advertisement
There are currently no qualifying experts in PHP
There are currently no qualifying experts in PHP
|
[x]
Posted via EE Mobile
|
||
Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
||
| 11/30/2007 at 07:57AM PST, ID: 22993323 |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: |
Example of desired XML result:
Before merge:
Old:
<xml version="1.0"/>
<preferences>
<setting1>value1</setting1>
<setting2 attr21="attr21Value" attr22="attr22Value" attr23="attr23Value"/>
</preferences>
New:
<xml version="1.0"/>
<preferences>
<setting1>value2</setting1>
<setting3 attr31="attrValue31" attr32="attr32Value" attr33="attrValue33"><setting31>value31</setting31><setting32>value32</setting32></setting3>
</preferences>
After merge:
<xml version="1.0"/>
<preferences>
<setting1>value2</setting1>
<setting2 attr21="attr21Value" attr22="attr22Value" attr23="attr23Value"/>
<setting3 attr31="attrValue31" attr32="attr32Value" attr33="attrValue33"><setting31>value31</setting31><setting32>value32</setting32></setting3>
</preferences>
-------------------
class UserPreferences
{
const DEFAULT_STRING = "<preferences/>";
$m_preferences = null;
public function __construct()
{
$this->m_preferences = new SimpleXMLElement(self::DEFAULT_STRING);
}
// $new is a SimpleXMLElement containing the preferences to be merged
public function merge($new)
{
$mergedDom = DOMDocument::loadXML(self::DEFAULT_STRING);
$oldDom = DOMDocument::loadXML($this->m_preferences->asXML());
// Compare existing/old preferences with the new
// preferences. If a match is found, delete the
// old preference.
foreach ($new->children() as $newChild)
{
$i = 0;
foreach ($this->m_preferences->children() as $oldChild)
{
if ($newChild->asXML() == $oldChild->asXML())
{
$oldDom->documentElement->removeChild($oldDom->documentElement->childNodes->item($i));
$i--;
}
else
{
$i++;
}
}
$newChildDom = DOMDocument::loadXML($newChild->asXML());
$mergedDom->documentElement->appendChild($mergedDom->importNode($newChildDom, true));
}
$this->m_preferences = simplexml_import_dom($oldDom);
foreach ($this->m_preferences->children() as $oldChild)
{
$oldChildDom = DOMDocument::loadXML($oldChild->asXML());
$mergedDom->documentElement->appendChild($mergedDom->importNode($oldChildDom, true));
}
$this->m_preferences = simplexml_import_dom($mergedDom);
}
}
|