Jump to content

Recommended Posts

  • 6 months later...
Posted

Using pugixml, here is some code for parsing a Visual Studio vcxproj file...

    auto buffer = LoadBuffer(filename);
     
    pugi::xml_document doc;
    pugi::xml_parse_result result = doc.load_buffer(buffer->Data(), buffer->GetSize());
    if (result.status == pugi::xml_parse_status::status_ok)
    {
        for (auto child : doc.children())
        {
            if (child != NULL and strcmp(child.name(), "Project") == 0)
            {
                Print(child.name());
                for (auto subchild : child.children())
                {
                    if (strcmp(subchild.name(), "ItemGroup") == 0)
                    {
                        Print("ItemGroup");
                        for (auto subsubchild : subchild.children())
                        {
                            if (strcmp(subsubchild.name(), "ClCompile") == 0)
                            {
                                auto attr = subsubchild.attribute("Include");
                                if (attr)
                                {
                                    std::string s = attr.as_string();
                                    if (ExtractExt(s) == "cpp")
                                    {
                                        Print(s);
                                        auto newnode = subchild.append_child("ClCompile");
                                        newnode.append_attribute("Include").set_value("Source/Components/Monster/MONSTER2.cpp");
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        out:
        std::ostringstream oss;
        doc.save(oss);
        std::string s = oss.str();
        Print(s);
    }

 

  • Like 1

Let's build cool stuff and have fun. :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...