Esempio n. 1
0
String AsXML(const XmlNode& node, dword style)
{
	StringBuffer r;
	if(style & XML_HEADER)
		r << XmlHeader();
	if(style & XML_DOCTYPE)
		for(int i = 0; i < node.GetCount(); i++) {
			const XmlNode& m = node.Node(i);
			if(m.GetType() == XML_TAG) {
				r << XmlDocType(m.GetText());
				break;
			}
		}
	style &= ~(XML_HEADER|XML_DOCTYPE);
	switch(node.GetType()) {
	case XML_PI:
		r << "<?" << node.GetText() << "?>\r\n";
		break;
	case XML_DECL:
		r << "<!" << node.GetText() << ">\r\n";
		break;
	case XML_COMMENT:
		r << "<!--" << node.GetText() << "-->\r\n";
		break;
	case XML_DOC:
		for(int i = 0; i < node.GetCount(); i++)
			r << AsXML(node.Node(i), style);
		break;
	case XML_TEXT:
		r << DeXml(node.GetText());
		break;
	case XML_TAG:
		XmlTag tag(node.GetText());
		for(int i = 0; i < node.GetAttrCount(); i++)
			tag(node.AttrId(i), node.Attr(i));
		if(node.GetCount()) {
			StringBuffer body;
			for(int i = 0; i < node.GetCount(); i++)
				body << AsXML(node.Node(i), style);
			r << tag(~body);
		}
		else
			r << tag();
	}
	return r;
}
Esempio n. 2
0
void Scan(const XmlNode& n, bool nano)
{
	for(int i = 0; i < n.GetCount(); i++) {
		total_len += n.GetText().GetCount();
		if(nano)
			ws.Add(ns.Add(n.GetText()));
		else
			ss.Add(n.GetText());
		if(n[i].IsTag()) {
			Scan(n[i], nano);
		}
	}
}
Esempio n. 3
0
void MakeMap(VectorMap<String, int>& map, const XmlNode& n, const String& path, int& tag_count, int& other_count)
{
	if(map.GetCount() > 1000)
		return;
	for(int i = 0; i < n.GetCount(); i++) {
		const Tuple2<int, String> *m = FindTuple(mm, __countof(mm), n[i].GetType());
		if(m) {
			count.GetAdd(m->b, 0)++;
			count.GetAdd(String(m->b) + ".len", 0) += n[i].GetText().GetCount();
		}
		if(n[i].IsTag()) {
			String np = path + "/" + n[i].GetTag();
			map.GetAdd(np, 0)++;
			MakeMap(map, n[i], np, tag_count, other_count);
			count.GetAdd("attr", 0) += n[i].GetAttrCount();
		}
		else
			map.GetAdd(path + ':' + (m ? m->b : "?"), 0)++;
	}
}