예제 #1
0
void mergeNodes(pugi::xml_node toNode, pugi::xml_node& fromNode)
{
  // Base case = both nodes are text nodes
  pugi::xml_text fromNodeText = fromNode.text();
  pugi::xml_text toNodeText = toNode.text();
  if (fromNodeText && toNodeText) {
    SBLog::info() << "Overwriting template value of \"" << toNode.name() << "\" from \"" << toNodeText.get() << "\" to \"" << fromNodeText.get() << "\"." << std::endl;
    toNodeText.set(fromNodeText.get());
    return;
  }

  // Calculate number of children in toNode
  unsigned maxDistance = std::distance(toNode.begin(), toNode.end());

  // Merge children
  for (pugi::xml_node fromNodeChild = fromNode.first_child(); fromNodeChild; fromNodeChild = fromNodeChild.next_sibling()) {
    // Find appropriate merge point
    pugi::xml_node toNodeChild = findSimilarNode(fromNodeChild, toNode, maxDistance);
    if (toNodeChild) {
      mergeNodes(toNodeChild, fromNodeChild);
    } else {
      toNode.append_copy(fromNodeChild);
    }
  }

  // Erase fromNode
  removeNode(fromNode);
}
예제 #2
0
void AddTextElementRaw(pugi::xml_node node, const char* value)
{
	wxASSERT(node);
	wxASSERT(value);

	if (*value)
		node.text().set(value);
	else {
		node.text().set("");
	}
}
예제 #3
0
void XmlTools::CopyXmlNode(const pugi::xml_node& srcNode, pugi::xml_node& dstNode)
{
    for (const pugi::xml_attribute& attr : srcNode.attributes())
    {
        auto attrCopy = dstNode.append_attribute(attr.name());
        attrCopy.set_value(attr.value());
    }
    for (const pugi::xml_node& node : srcNode.children())
    {
        auto nodeCopy = dstNode.append_child(node.name());
        CopyXmlNode(node, nodeCopy);
    }
    auto nodeText = srcNode.text();
    dstNode.text().set(nodeText.as_string());
}
예제 #4
0
파일: XmlReader.cpp 프로젝트: Debian/pbbam
static
void FromXml(const pugi::xml_node& xmlNode, DataSetElement& parent)
{
    // ignore non-named XML nodes
    //
    // pugi::xml separates XML parts into more node types than we use
    //
    const string& label = xmlNode.name();
    if (label.empty())
        return;

    // label & text
    DataSetElement e(xmlNode.name(), FromInputXml());
    e.Text(xmlNode.text().get());

    // iterate attributes
    auto attrIter = xmlNode.attributes_begin();
    auto attrEnd  = xmlNode.attributes_end();
    for ( ; attrIter != attrEnd; ++attrIter )
        e.Attribute(attrIter->name(), attrIter->value());

    // iterate children, recursively building up subtree
    auto childIter = xmlNode.begin();
    auto childEnd = xmlNode.end();
    for ( ; childIter != childEnd; ++childIter ) {
        pugi::xml_node childNode = *childIter;
        FromXml(childNode, e);
    }

    // add our element to its parent
    parent.AddChild(e);
}
예제 #5
0
void CDuiListBox::LoadItemAttribute(pugi::xml_node xmlNode, LPLBITEM pItem)
{
	pItem->nImage=xmlNode.attribute("img").as_int(pItem->nImage);
	pItem->lParam=xmlNode.attribute("data").as_uint(pItem->lParam);

    pItem->strText =  DUI_CA2T(xmlNode.text().get(), CP_UTF8);
    DuiStringPool::getSingleton().BuildString(pItem->strText);
}
예제 #6
0
BOOL RichEditText::InitFromXml(pugi::xml_node xmlNode)
{
    m_strText = xmlNode.text().get();

    // 计算行数
    for (int nlf = m_strText.Find(0x0a); nlf >= 0; ++m_nLineCount)
    {
        nlf = m_strText.Find(0x0a, nlf+1);
    }

    return __super::InitFromXml(xmlNode);
}
예제 #7
0
bool GraphMLParser::readData(
	GraphAttributes &GA,
	const edge &e,
	const pugi::xml_node edgeData)
{
	pugi::xml_attribute keyId = edgeData.attribute("key");
	if (!keyId) {
		GraphIO::logger.lout() << "Edge data does not have a key." << endl;
		return false;
	}

	const long attrs = GA.attributes();
	pugi::xml_text text = edgeData.text();

	switch(graphml::toAttribute(m_attrName[keyId.value()])) {
	case graphml::a_edgeLabel:
		if(attrs & GraphAttributes::edgeLabel) {
			GA.label(e) = text.get();
		}
		break;
	case graphml::a_edgeWeight:
		if(attrs & GraphAttributes::edgeIntWeight) {
			GA.intWeight(e) = text.as_int();
		} else if(attrs & GraphAttributes::edgeDoubleWeight) {
			GA.doubleWeight(e) = text.as_double();
		}
		break;
	case graphml::a_edgeType:
		if(attrs & GraphAttributes::edgeType) {
			GA.type(e) = graphml::toEdgeType(text.get());
		}
		break;
	case graphml::a_edgeArrow:
		if(attrs & GraphAttributes::edgeArrow) {
			GA.arrowType(e) = graphml::toArrow(text.get());
		}
		break;
	case graphml::a_edgeStroke:
		if(attrs & GraphAttributes::edgeStyle) {
			GA.strokeColor(e) = text.get();
		}
		break;
	default:
		GraphIO::logger.lout(Logger::LL_MINOR) << "Unknown edge attribute with \""
		             << keyId.value()
		             << "\"." << endl;
	}

	return true;
}
예제 #8
0
bool GraphMLParser::readData(
	GraphAttributes &GA,
	const node &v, 
	const pugi::xml_node nodeData)
{
	pugi::xml_attribute keyId = nodeData.attribute("key");

	if (!keyId) {
		GraphIO::logger.lout() << "Node data does not have a key." << endl;
		return false;
	}

	const long attrs = GA.attributes();

	pugi::xml_text text = nodeData.text();

	switch (graphml::toAttribute(m_attrName[keyId.value()])) {
	case graphml::a_nodeLabel:
		if(attrs & GraphAttributes::nodeLabel) {
			GA.label(v) = text.get();
		}
		break;
	case graphml::a_x:
		if(attrs & GraphAttributes::nodeGraphics) {
			GA.x(v) = text.as_double();
		}
		break;
	case graphml::a_y:
		if(attrs & GraphAttributes::nodeGraphics) {
			GA.y(v) = text.as_double();;
		}
		break;
	case graphml::a_width:
		if(attrs & GraphAttributes::nodeGraphics) {
			GA.width(v) = text.as_double();
		}
		break;
	case graphml::a_height:
		if(attrs & GraphAttributes::nodeGraphics) {
			GA.height(v) = text.as_double();
		}
		break;
	case graphml::a_size:
		if(attrs & GraphAttributes::nodeGraphics) {
			double size = text.as_double();

			// We want to set a new size only if width and height was not set.
			if (GA.height(v) == GA.width(v)) {
				GA.height(v) = GA.width(v) = size;
			}
		}
		break;
	case graphml::a_shape:
		if(attrs & GraphAttributes::nodeGraphics) {
			GA.shape(v) = graphml::toShape(text.get());
		}
		break;
	case graphml::a_z:
		if(attrs & GraphAttributes::threeD) {
			GA.z(v) = text.as_double();
		}
		break;
	case graphml::a_r:
		if (attrs & GraphAttributes::nodeStyle
		 && !GraphIO::setColorValue(text.as_int(), [&](uint8_t val) { GA.fillColor(v).red(val); })) {
			return false;
		}
		break;
	case graphml::a_g:
		if(attrs & GraphAttributes::nodeStyle
		 && !GraphIO::setColorValue(text.as_int(), [&](uint8_t val) { GA.fillColor(v).green(val); })) {
			return false;
		}
		break;
	case graphml::a_b:
		if(attrs & GraphAttributes::nodeStyle
		 && !GraphIO::setColorValue(text.as_int(), [&](uint8_t val) { GA.fillColor(v).blue(val); })) {
			return false;
		}
		break;
	case graphml::a_nodeFill:
		if(attrs & GraphAttributes::nodeStyle) {
			GA.fillColor(v) = text.get();
		}
		break;
	case graphml::a_nodeStroke:
		if(attrs & GraphAttributes::nodeStyle) {
			GA.strokeColor(v) = text.get();
		}
		break;
	case graphml::a_nodeType:
		if(attrs & GraphAttributes::nodeType) {
			GA.type(v) = graphml::toNodeType(text.get());
		}
		break;
	case graphml::a_template:
		if(attrs & GraphAttributes::nodeTemplate) {
			GA.templateNode(v) = text.get();
		}
		break;
	case graphml::a_nodeWeight:
		if(attrs & GraphAttributes::nodeWeight) {
			GA.weight(v) = text.as_int();
		}
		break;
	default:
		GraphIO::logger.lout(Logger::LL_MINOR) << "Unknown node attribute: \"" << keyId.value() << "\"." << endl;
	}

	return true;
}
예제 #9
0
bool GraphMLParser::readData(
	ClusterGraphAttributes &CA,
	const cluster &c,
	const pugi::xml_node clusterData)
{
	auto keyId = clusterData.attribute("key");
	if (!keyId) {
		GraphIO::logger.lout() << "Cluster data does not have a key." << endl;
		return false;
	}

	pugi::xml_text text = clusterData.text();

	using namespace graphml;
	switch (toAttribute(m_attrName[keyId.value()])) {
	case a_nodeLabel:
		CA.label(c) = text.get();
		break;
	case a_x:
		CA.x(c) = text.as_double();
		break;
	case a_y:
		CA.y(c) = text.as_double();
		break;
	case a_width:
		CA.width(c) = text.as_double();
		break;
	case a_height:
		CA.height(c) = text.as_double();
		break;
	case a_size:
		// We want to set a new size only if width and height was not set.
		if (CA.width(c) == CA.height(c)) {
			CA.width(c) = CA.height(c) = text.as_double();
		}
	case a_r:
		if (!GraphIO::setColorValue(text.as_int(), [&](uint8_t val) { CA.fillColor(c).red(val); })) {
			return false;
		}
		break;
	case a_g:
		if (!GraphIO::setColorValue(text.as_int(), [&](uint8_t val) { CA.fillColor(c).green(val); })) {
			return false;
		}
		break;
	case a_b:
		if (!GraphIO::setColorValue(text.as_int(), [&](uint8_t val) { CA.fillColor(c).blue(val); })) {
			return false;
		}
		break;
	case a_clusterStroke:
		CA.strokeColor(c) = text.get();
		break;
	default:
		GraphIO::logger.lout(Logger::LL_MINOR) << "Unknown cluster attribute with \""
		             << keyId.value()
		             << "--enum: " << m_attrName[keyId.value()] << "--"
		             << "\"." << endl;
	}

	return true;
}
예제 #10
0
void AddTextElementUtf8(pugi::xml_node node, std::string const& value)
{
	assert(node);
	node.text().set(value.c_str());
}
예제 #11
0
void AddTextElement(pugi::xml_node node, int64_t value)
{
	assert(node);
	node.text().set(static_cast<long long>(value));
}
예제 #12
0
    virtual bool for_each(pugi::xml_node& node) {

        Log::log(logModule, level, "XML node type = [%s], name = [%s], value = [%s]",
                node_types[node.type()], node.name(), 
                node.type() == pugi::node_cdata || node.type() == pugi::node_pcdata ? node.text().get() : node.value());
        for (pugi::xml_attribute_iterator ait = node.attributes_begin(); ait != node.attributes_end(); ++ait) {
            Log::log(logModule, level, "  attribute name = [%s], value = [%s]",
                    ait->name(), ait->value());
        }
        return true;
    }