Exemple #1
0
static XmlNode sReadXmlNode(XmlParser& p, dword style)
{
	XmlNode m;
	if(p.IsTag()) {
		m.CreateTag(p.ReadTag());
		m.SetAttrsPick(p.PickAttrs());
		while(!p.End())
			if(!Ignore(p, style))
				m.Add() = sReadXmlNode(p, style);
		return m;
	}
	if(p.IsPI()) {
		m.CreatePI(p.ReadPI());
		return m;
	}
	if(p.IsDecl()) {
		m.CreateDecl(p.ReadDecl());
		return m;
	}
	if(p.IsComment()) {
		m.CreateComment(p.ReadComment());
		return m;
	}
	m.CreateText(p.ReadText());
	return m;
}
Exemple #2
0
void XmlView::Load(int parent, XmlParser& p)
{
	if(p.IsTag()) {
		String tag = p.ReadTag();
		String txt = tag;
		for(int i = 0; i < p.GetAttrCount(); i++)
			txt << ' ' << p.GetAttr(i) << "=\"" << p[i] << "\"";
		parent = xml.Add(parent, XmlImg::Tag(), tag, txt);
		while(!p.End()) {
			if(p.IsEof())
				throw XmlError("");
			Load(parent, p);
		}
	}
	else
	if(p.IsText())
		xml.Add(parent, XmlImg::Text(), Null, NormalizeSpaces(p.ReadText()));
	else
	if(p.IsPI())
		xml.Add(parent, XmlImg::PI(), Null, NormalizeSpaces(p.ReadPI()));
	else
	if(p.IsDecl())
		xml.Add(parent, XmlImg::Decl(), Null, NormalizeSpaces(p.ReadDecl()));
	else
	if(p.IsComment())
		xml.Add(parent, XmlImg::Comment(), Null, NormalizeSpaces(p.ReadComment()));
	else
		NEVER();
}
/**
* parse the special value "struc". this method parses the complexer value "struct" and returns it
* @param p XmlParser holding the xml document
* @return the parsed struct as Value (not ValueMap!)
*/
Value XmlRpcParser::ParseStruct(XmlParser& p) {
	ValueMap vm;
	Value key, data;
	while(p.Tag("member")) {
		for(int i=0;i<2;i++){
			if(p.Tag("name")) {
				key = Value(p.ReadText());
				p.PassEnd(); //name
			} else
				data = Parse(p);
		}
		p.PassEnd(); //member
		vm.Add(key,data);
	}
	return Value(vm);
}
/**
* parse primitve. this method parses the values, that are stored inside the Xml-document
* handled by the XmlParser \p p.
* @param p the parser holding the xml document
* @return the Value contained in the xml document
*/
Value XmlRpcParser::ParsePrimitive(XmlParser& p) {
	Value v,vv;
	if(p.IsText()) {
		return Value(p.ReadText());
	}
	for(int i=0;i<7;i++) {
		if(p.Tag(primitives[i])) {
			switch(i) {
			case 0: //string
				v=Value(p.ReadText());
				break;
			case 1: //int
			case 2: //i4
				v = Value(atoi(p.ReadText()));
				break;
			case 3: //boolean
				v = Value((bool)atoi(p.ReadText()));
				break;
			case 4: //double
				v = Value(atof(p.ReadText()));
				break;
			case 5: //dateTime.iso8601
				p.ReadTextE();
				v=Value(Date(1970,1,1));
				break;
			case 6: //base64
				LoadFromString(vv, p.ReadText());
				v = Value(vv);
				break;
			default:
				throw Exc("unexpected Error");
				break;
			}
			p.PassEnd();
			return Value(v);
		}
	}
	throw Exc("unknown primitive");
}
Exemple #5
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;
}