Пример #1
0
 static QString tagString( const pugi::xpath_node& node ) {
     QString tag = QString( "<%1" ).arg( node.node().name() );
     for ( auto a : node.node().attributes() )
         tag.append( QString( " %1=\"%2\"" ).arg( a.name(), a.value() ) );
     tag.append( ">" );                
     return tag;
 }
Пример #2
0
void Procedure::load(const pugi::xpath_node& node)
{
    name_ = node.node().attribute("name").value();
    pugi::xpath_node_set lines = node.node().select_nodes("body/child::*");

    for(auto line : lines) {
        body_ += line.node().child_value();
        body_ += "\n";
    }
}
Пример #3
0
  std::string Engine::getNode( const pugi::xml_document& cfg,
      const std::string xpath ) {
    const pugi::xpath_node xpnode = cfg.select_single_node(xpath.c_str()) ;

    DLOG(INFO) << xpath << " " <<  xpnode.node().name() << " "
      << xpnode.node().last_child().value() << std::endl ;

    std::string ret(xpnode.node().last_child().value());
    if( ret.size( ) == 0 ) {
      throw StatMissingException( "xpath [" + xpath + "] returns no value." ) ;
    }
    return ret ;
  }
Пример #4
0
void XMLFile::PatchRemove(const pugi::xpath_node& original) const
{
    // If no attribute but node then its a node, otherwise its an attribute or null
    if (!original.attribute() && original.node())
    {
        pugi::xml_node parent = original.parent();
        parent.remove_child(original.node());
    }
    else if (original.attribute())
    {
        pugi::xml_node parent = original.parent();
        parent.remove_attribute(original.attribute());
    }
}
Пример #5
0
            void operator()( const pugi::xpath_node& node, const QModelIndex& parent ) const {

                int row = model.rowCount( parent );

                model.insertRow( row, parent );
                model.setData( model.index( row, 0, parent ), node.node().name() );
                model.setData( model.index( row, 1, parent ), node.node().text().get() );

                for ( auto child : node.node().select_nodes( "./*" ) ) {
                    model.itemFromIndex( model.index( row, 0, parent ) )->setColumnCount( 2 );
                    (*this)(child, model.index( row, 0, parent ));
                }

            }
Пример #6
0
void XMLFile::PatchReplace(const pugi::xml_node& patch, pugi::xpath_node& original) const
{
    // If no attribute but node then its a node, otherwise its an attribute or null
    if (!original.attribute() && original.node())
    {
        pugi::xml_node parent = original.node().parent();

        parent.insert_copy_before(patch.first_child(), original.node());
        parent.remove_child(original.node());
    }
    else if (original.attribute())
    {
        original.attribute().set_value(patch.child_value());
    }
}
Пример #7
0
 void operator()( const pugi::xpath_node& node, int level = 0 ) const {
     QTextCursor cursor = edit.textCursor();
     QString name( node.node().name() );
     if ( name != "svg" ) {
         QString text( node.node().text().get() );
         if ( !text.isEmpty() ) {
             // cursor.insertText( name, paragraphFormat );
             cursor.insertText( text, paragraphFormat );
         }
         // process childlen
         for ( auto& child : node.node().select_nodes( "./*" ) ) {
             (*this)(child, level + 1);
         }
     }
 }
Пример #8
0
            void operator()( const pugi::xpath_node& node, QTextFrame * pframe = 0, int level = 0 ) const {

                QTextCursor cursor = edit.textCursor();
                if ( pframe )
                    cursor = pframe->lastCursorPosition();

                cursor.insertText( tagString( node ), tagFormat ); // <----------- <tag>

                auto frame = cursor.insertFrame( frameFormat );    // <-------------- insert frame
                QObject::connect( frame, &QTextFrame::destroyed, &edit, &docEdit::handleBlockDeleted );
                
                // body
                if ( std::strcmp( node.node().name(), "title" ) == 0 ) {

                    cursor.insertText( QString::fromStdString( node.node().text().get() ), headingFormat );
                }
                else if ( std::strcmp( node.node().name(), "paragraph" ) == 0 ) {

                    cursor.insertText( QString::fromStdString( node.node().text().get() ), paragraphFormat );
                }
                else {

                    cursor.insertText( QString::fromStdString( node.node().text().get() ), plainFormat );
                }

                // process childlen 
                for ( auto& child : node.node().select_nodes( "./*" ) ) {
                    (*this)(child, frame, level + 1);
                }
                cursor = pframe ? pframe->lastCursorPosition() : mainFrame->lastCursorPosition();
                cursor.insertText( QString( "</%1>" ).arg( node.node().name() ), tagFormat ); // </tag>
            }
Пример #9
0
void XMLFile::AddAttribute(const pugi::xml_node& patch, const pugi::xpath_node& original) const
{
    pugi::xml_attribute attribute = patch.attribute("type");

    if (!patch.first_child() && patch.first_child().type() != pugi::node_pcdata)
    {
        URHO3D_LOGERRORF("XML Patch failed calling Add due to attempting to add non text to an attribute for %s.", attribute.value());
        return;
    }

    String name(attribute.value());
    name = name.Substring(1);

    pugi::xml_attribute newAttribute = original.node().append_attribute(name.CString());
    newAttribute.set_value(patch.child_value());
}
Пример #10
0
void RbHelpParser::parseInternalHelpType(const pugi::xpath_node &node, RbHelpType *helpEntry)
{
    
    // name
    helpEntry->setName( node.node().select_single_node( "name" ).node().child_value() );
    
    // title
    helpEntry->setTitle( node.node().select_single_node( "title" ).node().child_value() );
    
    // aliases
    pugi::xpath_node_set nodeSet = node.node().select_nodes( "alias" );
    std::vector<std::string> aliases = std::vector<std::string>();
    for (pugi::xpath_node_set::const_iterator it = nodeSet.begin(); it != nodeSet.end(); ++it)
    {
        pugi::xpath_node subNode = *it;
        std::string alias = std::string(subNode.node().child_value());
        aliases.push_back( alias );
    }
    helpEntry->setAliases( aliases );
    
    // description
    std::vector<std::string> desc = std::vector<std::string>();
    nodeSet = node.node().select_nodes( "description/p" );
    for (pugi::xpath_node_set::const_iterator it = nodeSet.begin(); it != nodeSet.end(); ++it)
    {
        pugi::xpath_node subnode = *it;
        desc.push_back(subnode.node().child_value());
    }
    helpEntry->setDescription( desc );
    
    
    std::vector<RbHelpFunction> constructors;
    nodeSet = node.node().select_nodes( "constructor-help-entry" );
    for (pugi::xpath_node_set::const_iterator it = nodeSet.begin(); it != nodeSet.end(); ++it)
    {
        pugi::xpath_node node = *it;
        RbHelpFunction helpEntryConstructor = parseInternalHelpFunction( node );
        constructors.push_back( helpEntryConstructor );
    }
    // set the constructors
    helpEntry->setConstructors( constructors );
    

    std::vector<RbHelpFunction> methods;
    nodeSet = node.node().select_nodes( "method-help-entry" );
    for (pugi::xpath_node_set::const_iterator it = nodeSet.begin(); it != nodeSet.end(); ++it)
    {
        pugi::xpath_node node = *it;
        RbHelpFunction helpEntryMethod = parseInternalHelpFunction( node );
        methods.push_back( helpEntryMethod );
    }
    // set the methods
    helpEntry->setMethods( methods );
        
}
Пример #11
0
void XMLFile::AddNode(const pugi::xml_node& patch, const pugi::xpath_node& original) const
{
    // If pos is null, append or prepend add as a child, otherwise add before or after, the default is to append as a child
    pugi::xml_attribute pos = patch.attribute("pos");
    if (!pos || strlen(pos.value()) <= 0 || strcmp(pos.value(), "append") == 0)
    {
        pugi::xml_node::iterator start = patch.begin();
        pugi::xml_node::iterator end = patch.end();

        // There can not be two consecutive text nodes, so check to see if they need to be combined
        // If they have been we can skip the first node of the nodes to add
        if (CombineText(patch.first_child(), original.node().last_child(), false))
            start++;

        for (; start != end; start++)
            original.node().append_copy(*start);
    }
    else if (strcmp(pos.value(), "prepend") == 0)
    {
        pugi::xml_node::iterator start = patch.begin();
        pugi::xml_node::iterator end = patch.end();

        // There can not be two consecutive text nodes, so check to see if they need to be combined
        // If they have been we can skip the last node of the nodes to add
        if (CombineText(patch.last_child(), original.node().first_child(), true))
            end--;

        pugi::xml_node pos = original.node().first_child();
        for (; start != end; start++)
            original.node().insert_copy_before(*start, pos);
    }
    else if (strcmp(pos.value(), "before") == 0)
    {
        pugi::xml_node::iterator start = patch.begin();
        pugi::xml_node::iterator end = patch.end();

        // There can not be two consecutive text nodes, so check to see if they need to be combined
        // If they have been we can skip the first node of the nodes to add
        if (CombineText(patch.first_child(), original.node().previous_sibling(), false))
            start++;

        // There can not be two consecutive text nodes, so check to see if they need to be combined
        // If they have been we can skip the last node of the nodes to add
        if (CombineText(patch.last_child(), original.node(), true))
            end--;

        for (; start != end; start++)
            original.parent().insert_copy_before(*start, original.node());
    }
    else if (strcmp(pos.value(), "after") == 0)
    {
        pugi::xml_node::iterator start = patch.begin();
        pugi::xml_node::iterator end = patch.end();

        // There can not be two consecutive text nodes, so check to see if they need to be combined
        // If they have been we can skip the first node of the nodes to add
        if (CombineText(patch.first_child(), original.node(), false))
            start++;

        // There can not be two consecutive text nodes, so check to see if they need to be combined
        // If they have been we can skip the last node of the nodes to add
        if (CombineText(patch.last_child(), original.node().next_sibling(), true))
            end--;

        pugi::xml_node pos = original.node();
        for (; start != end; start++)
            pos = original.parent().insert_copy_after(*start, pos);
    }
}
Пример #12
0
int processProductsSubtableXML(pugi::xpath_node node, int recordPK, std::vector<int>& subtablePKs)
{
	DbAccess* m_dbAccess = getDBAccess();
    if(m_dbAccess==NULL)
        return 2;      
	int ret = 0;

	// Get the Attribute Element Child belonging to each Record
	bool needPrimaryKeys = false;
	if (subtablePKs.empty())
	{
		needPrimaryKeys = true;
		subtablePKs.push_back(0);
		subtablePKs.push_back(0);
	}
	int& attributePK = subtablePKs[0];
	int& defaultAttributePK = subtablePKs[1];
	if (needPrimaryKeys)
	{
		Rows rows;
		m_dbAccess->executeSqlQuery("SELECT MAX(PrimaryKey) AS PrimaryKey FROM ProductAttribute", rows);
		if (!rows.empty())
			attributePK = convertStringToU32(rows.front()["PrimaryKey"]);
		rows.clear();
		m_dbAccess->executeSqlQuery("SELECT MAX(PrimaryKey) AS PrimaryKey FROM ProductDefaultAttribute", rows);
		if (!rows.empty())
			defaultAttributePK = convertStringToU32(rows.front()["PrimaryKey"]);
	}

	for (pugi::xml_node tool = node.node().first_child(); tool; tool = tool.next_sibling())
	{
		std::string childName(tool.name());

		if (childName.compare("Attribute") == 0)
		{
			std::string s_queryAttribute = "";
			std::string s_queryColumn = "";
			std::string s_queryValue = "";

			attributePK++;
			int attributeCount = 0;
			for (pugi::xml_attribute attr = tool.first_attribute(); attr; attr = attr.next_attribute())
			{
				if(attributeCount > 0)
				{
					s_queryColumn += ",";
					s_queryValue += ",";
				}
				s_queryColumn.append("'");
				s_queryColumn += attr.name();
				s_queryColumn.append("'");
				s_queryValue += sqlify(attr.value());
				attributeCount++;
			}
			s_queryAttribute = "INSERT INTO ProductAttribute('PrimaryKey',";
			s_queryAttribute += s_queryColumn;
			s_queryAttribute += ",'FK_ProductRecord') VALUES ('";
			s_queryAttribute += static_cast<std::ostringstream*>( &(std::ostringstream() << attributePK) )->str(); // PK for Device Parameter Attribute
			s_queryAttribute += "',";
			s_queryAttribute += s_queryValue;
			s_queryAttribute += ",'";
			s_queryAttribute += static_cast<std::ostringstream*>( &(std::ostringstream() << recordPK) )->str(); // FK to Device Parameter Record
			s_queryAttribute += "'";
			s_queryAttribute += ")";

			// std::cout << "\n" << s_queryDeviceParameterAttribute;
		    if ( m_dbAccess->executeSqlInsert(s_queryAttribute) != 0 )
			{
				CsErrx("Query '%s' failed", s_queryAttribute.c_str());
				ret = 2;
			}
		}
		else if (childName.compare("DefaultAttribute") == 0)
		{
			std::string s_queryDefaultAttribute = "";
			std::string s_queryColumn = "";
			std::string s_queryValue = "";

			defaultAttributePK++;
			int attributeCount = 0;
			for (pugi::xml_attribute attr = tool.first_attribute(); attr; attr = attr.next_attribute())
			{
				if(attributeCount > 0)
				{
					s_queryColumn += ",";
					s_queryValue += ",";
				}
				s_queryColumn.append("'");
				s_queryColumn += attr.name();
				s_queryColumn.append("'");
				s_queryValue += sqlify(attr.value());
				attributeCount++;
			}
			s_queryDefaultAttribute = "INSERT INTO ProductDefaultAttribute('PrimaryKey',";
			s_queryDefaultAttribute += s_queryColumn;
			s_queryDefaultAttribute += ",'FK_ProductRecord') VALUES ('";
			s_queryDefaultAttribute += static_cast<std::ostringstream*>( &(std::ostringstream() << defaultAttributePK) )->str(); // PK for Device Parameter Attribute
			s_queryDefaultAttribute += "',";
			s_queryDefaultAttribute += s_queryValue;
			s_queryDefaultAttribute += ",'";
			s_queryDefaultAttribute += static_cast<std::ostringstream*>( &(std::ostringstream() << recordPK) )->str(); // FK to Device Parameter Record
			s_queryDefaultAttribute += "'";
			s_queryDefaultAttribute += ")";

			// std::cout << "\n" << s_queryDeviceParameterAttribute;
		    if ( m_dbAccess->executeSqlInsert(s_queryDefaultAttribute) != 0 )
			{
				CsErrx("Query '%s' failed", s_queryDefaultAttribute.c_str());
				ret = 2;
			}
		}
	}

	return ret;
}
Пример #13
0
void shader_configuration::serialize_xml(pugi::xml_document& document, pugi::xpath_node& node)
{
std::string filename = node.node().attribute("filename").as_string();
configuration::set_attribute("/shader/filename", std::make_shared<configuration_attribute>(filename));
}
Пример #14
0
RbHelpFunction RbHelpParser::parseInternalHelpFunction(const pugi::xpath_node &node)
{
    // create the help function entry that we will fill with some values later on
    RbHelpFunction helpEntry = RbHelpFunction();
    
    pugi::xpath_node_set nodeSet, subSet;
    
    std::string entry = "";
    
    // name
    helpEntry.setName( node.node().select_single_node( "name" ).node().child_value() );
    
    // aliases
    nodeSet = node.node().select_nodes( "alias" );
    std::vector<std::string> aliases = std::vector<std::string>();
    for (pugi::xpath_node_set::const_iterator it = nodeSet.begin(); it != nodeSet.end(); ++it)
    {
        pugi::xpath_node subNode = *it;
        std::string alias = std::string(subNode.node().child_value());
        aliases.push_back( alias );
    }
    helpEntry.setAliases( aliases );
    
    // title
    helpEntry.setTitle( node.node().select_single_node( "title" ).node().child_value() );
    
    // description
    std::vector<std::string> desc = std::vector<std::string>();
    nodeSet = node.node().select_nodes( "description/p" );
    for (pugi::xpath_node_set::const_iterator it = nodeSet.begin(); it != nodeSet.end(); ++it)
    {
        pugi::xpath_node subnode = *it;
        desc.push_back(subnode.node().child_value());
    }
    helpEntry.setDescription( desc );
    
    // usage
    helpEntry.setUsage( node.node().select_single_node( "usage" ).node().child_value() );
    
    // arguments
    nodeSet = node.node().select_nodes( "argument" );
    int loop = 1;
    std::vector<RbHelpArgument> arguments = std::vector<RbHelpArgument>();
    for (pugi::xpath_node_set::const_iterator it = nodeSet.begin(); it != nodeSet.end(); ++it)
    {
        pugi::xpath_node subnode = *it;
        RbHelpArgument argument = RbHelpArgument();
        argument.setLabel(                  subnode.node().child_value("label")                    );
        argument.setDescription(            subnode.node().child_value("description")              );
        argument.setArgumentDagNodeType(    subnode.node().child_value("argumentNodeType")         );
        argument.setArgumentPassingMethod(  subnode.node().child_value("argumentPassingMethod")    );
        argument.setValueType(              subnode.node().child_value("valueType")                );
        argument.setDefaultValue(           subnode.node().child_value("defaultValue")             );
        
        // loop options
        std::vector<std::string> options = std::vector<std::string>();
        std::string s =  "argument[" + StringUtilities::to_string(loop) + "]/option"; // xpath search expression
        subSet = subnode.node().select_nodes( s.c_str() );
        for (pugi::xpath_node_set::const_iterator it = subSet.begin(); it != subSet.end(); ++it)
        {
            pugi::xpath_node subsubNode = *it;
            std::string option = std::string( subsubNode.node().child_value() );
            options.push_back( option );
        }
        argument.setOptions( options );
        
        // add the argument to the argument list
        arguments.push_back( argument );
        
        loop++;
    }
    helpEntry.setArguments( arguments );
    
    // return value
    helpEntry.setReturnType( node.node().select_single_node( "returnValue" ).node().child_value());
    
    // details
    std::vector<std::string> details = std::vector<std::string>();
    nodeSet = node.node().select_nodes( "details/p" );
    for (pugi::xpath_node_set::const_iterator it = nodeSet.begin(); it != nodeSet.end(); ++it) {
        pugi::xpath_node subnode = *it;
        details.push_back( subnode.node().child_value());
    }
    helpEntry.setDetails( details );
    
    // example
    helpEntry.setExample( node.node().select_single_node( "example" ).node().child_value());
    
    // reference
    std::vector<RbHelpReference> references = std::vector<RbHelpReference>();
    nodeSet = node.node().select_nodes( "reference" );
    for (pugi::xpath_node_set::const_iterator it = nodeSet.begin(); it != nodeSet.end(); ++it)
    {
        pugi::xpath_node subnode = *it;
        RbHelpReference ref = RbHelpReference();
        
        ref.setCitation( subnode.node().child_value("citation") );
        ref.setDoi( subnode.node().child_value("doi") );
        ref.setUrl( subnode.node().child_value("url") );
        references.push_back( ref );
    }
    helpEntry.setReferences( references );
    
    // author
    helpEntry.setAuthor( node.node().select_single_node( "author" ).node().child_value());
    
    // see also
    std::vector<std::string> seeAlso = std::vector<std::string>();
    nodeSet = node.node().select_nodes( "seeAlso/entry" );
    for (pugi::xpath_node_set::const_iterator it = nodeSet.begin(); it != nodeSet.end(); ++it)
    {
        pugi::xpath_node subnode = *it;
        seeAlso.push_back( subnode.node().child_value());
    }
    helpEntry.setSeeAlso(seeAlso);
    
    
    
    return helpEntry;
}