File: xml_utility.cpp

package info (click to toggle)
k3d 0.4.3.0-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 51,716 kB
  • ctags: 81,610
  • sloc: cpp: 283,698; ansic: 64,095; xml: 61,533; sh: 9,026; makefile: 5,282; python: 431; perl: 308; awk: 130
file content (51 lines) | stat: -rw-r--r-- 1,262 bytes parent folder | download
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
#include "xml_utility.h"

#include <sdpxml/sdpxml.h>

namespace k3d
{

namespace xml
{

sdpxml::Element& safe_element(sdpxml::Element& Parent, const std::string& Name)
{
	return safe_element(Parent, sdpxml::Element(Name));
}

sdpxml::Element& safe_element(sdpxml::Element& Parent, const sdpxml::Element& Search)
{
	return safe_element(Parent, Search, Search);
}

sdpxml::Element& safe_element(sdpxml::Element& Parent, const sdpxml::Element& Search, const sdpxml::Element& Prototype)
{
	for(sdpxml::ElementCollection::iterator child = Parent.Children().begin(); child != Parent.Children().end(); ++child)
		{
			if(child->Name() != Search.Name())
				continue;
				
			sdpxml::AttributeCollection::const_iterator search_attribute;
			for(search_attribute = Search.Attributes().begin(); search_attribute != Search.Attributes().end(); ++search_attribute)
				{
					sdpxml::AttributePointer attribute = sdpxml::FindAttribute(*child, sdpxml::SameName(search_attribute->Name()));
					if(!attribute)
						break;

					if(attribute->Value() != search_attribute->Value())
						break;
				}
				
			if(search_attribute != Search.Attributes().end())
				continue;
				
			return *child;
		}

	return Parent.Append(Prototype);
}

} // namespace xml

} // namespace k3d