Beispiel #1
0
Value ParseXmlRpcParam(XmlParser& p)
{
	p.PassTag("param");
	Value v = ParseXmlRpcValue(p);
	p.PassEnd();
	return v;
	}
Beispiel #2
0
/**
* parse the special value "array". this method parses the complexer value "array" and returns it
* @param p XmlParser holding the xml document
* @return the parsed array as Value (not ValueArray!)
*/
Value XmlRpcParser::ParseArray(XmlParser& p) {
	ValueArray va;
	p.PassTag("data");
	while(!p.End()) {
		Value v = Parse(p);
		va.Add(v);
	}
	return Value(va);
}
Beispiel #3
0
/**
* parse every possible value. this method parses every possible value (defined by the xmlrpc standard)
* and returns it. This is done by calling the special functions ParsePrimitive(), ParseArray()
* and ParseStruct().
* @param p XmlParser holding the xml document
* @return the parsed Value
*/
Value XmlRpcParser::Parse(XmlParser& p) {
	Value v;
	p.PassTag("value");
	if(p.Tag("struct")) {
		v=ParseStruct(p);
		p.PassEnd(); //struct
	}
	else if(p.Tag("array")) {
		v=ParseArray(p);
		p.PassEnd(); //array
	}
	else
		v=ParsePrimitive(p);
	p.PassEnd(); //value
	return Value(v);
}
Beispiel #4
0
NAMESPACE_UPP

Value ParseXmlRpcValue(XmlParser& p)
{
	Value r;
	p.PassTag("value");
	if(p.Tag("int") || p.Tag("i4")) {
		String s = p.ReadText();
		CParser p(s);
		if(!p.IsInt())
			throw XmlError("integer expected");
		r = p.ReadInt();
	}
	else
	if(p.Tag("boolean")) {
		int n = StrInt(p.ReadText());
		if(n != 0 && n != 1)
			throw XmlError("boolean expected");
		r = (bool)n;
	}
	else
	if(p.Tag("double")) {
		String s = p.ReadText();
		CParser p(s);
		if(!p.IsDouble())
			throw XmlError("double expected");
		r = p.ReadDouble();
	}
	else
	if(p.Tag("string") || p.Tag("base64"))
		r = p.ReadText();
	else
	if(p.TagE("nil")) {
		p.PassEnd();
		return r;
	}
	else
	if(p.Tag("dateTime.iso8601")) {
		String s = TrimBoth(p.ReadText());
		// 19980717T14:08:55
		// 01234567890123456
		if(s.GetCount() != 17 || s[8] != 'T' || s[11] != ':' || s[14] != ':')
			throw XmlError("invalid dateTime format");
		Time tm;
		tm.year = atoi(s.Mid(0, 4));
		tm.month = atoi(s.Mid(4, 2));
		tm.day = atoi(s.Mid(6, 2));
		tm.hour = atoi(s.Mid(9, 2));
		tm.minute = atoi(s.Mid(12, 2));
		tm.second = atoi(s.Mid(15, 2));
		r = tm;
	}
	else
	if(p.Tag("array")) {
		ValueArray va;
		p.PassTag("data");
		while(!p.End())
			va.Add(ParseXmlRpcValue(p));
		r = va;
	}
	else
	if(p.Tag("struct")) {
		ValueMap vm;
		while(p.Tag("member")) {
			p.PassTag("name");
			String name = p.ReadText();
			p.PassEnd();
			vm.Add((Value)name, ParseXmlRpcValue(p));
			p.PassEnd();
		}
		r = vm;
	}
	else
		throw XmlError("unknown value type");
	p.PassEnd();
	p.PassEnd();
	return r;
}