在Qt中解析* .vcproj文件

时间:2013-11-19 10:15:11

标签: qt parsexml qxmlstreamreader

我需要在Qt中解析.vcproj文件,这个文件实际上是xml文件adn看起来像:

<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioProject...>
    <Platforms>
        <Platform
            Name="Win32"
        />
    </Platforms>
    <ToolFiles>
    </ToolFiles>
    <Configurations>
        <Configuration
            Name="Debug|Win32"
            OutputDirectory="$(SolutionDir)$(ConfigurationName)"
            IntermediateDirectory="$(ConfigurationName)"
            ConfigurationType="1"
            CharacterSet="2"
            >
            ...
        </Configuration>
        <Configuration
            Name="Release|Win32"
            OutputDirectory="$(SolutionDir)$(ConfigurationName)"
            IntermediateDirectory="$(ConfigurationName)"
            ConfigurationType="1"
            CharacterSet="2"
            WholeProgramOptimization="1"
            >
            ...
        </Configuration>
    </Configurations>
    <References>
    </References>
    <Files>
        <Filter
            Name="Source Files"
            Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
            UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
            >
            ...
        </Filter>
        <Filter
            Name="CppOp"
            >
            ...
        </Filter>
    </Files>
    <Globals>
    </Globals>
</VisualStudioProject>

我需要获取所有配置名称,我使用它:

QFile* file = new QFile(xmlFile);
    if (file->open(QIODevice::ReadOnly | QIODevice::Text)) {
        QXmlStreamReader xml(file);
        while (!xml.atEnd() && !xml.hasError()){
            QXmlStreamReader::TokenType token = xml.readNext();
            if (token == QXmlStreamReader::StartDocument)
                continue;
            if (token == QXmlStreamReader::StartElement) {
                if (xml.name() == "Configurations")
                    continue;
                if (xml.name() == "Configuration") {
                    QXmlStreamAttributes attributes = xml.attributes();
                    if (attributes.hasAttribute("Name"))
                        ui->prefferedConfigSelectComboBox->addItem(attributes.value("Name").toString());
                }
            }
        }
    }

我尝试使用http://developer.nokia.com/Community/Wiki/QXmlStreamReader_to_parse_XML_in_Qt。它看起来像QXmlStreamReader没有“看到”此文件中的Name属性。 但它不起作用,我不知道为什么。

0 个答案:

没有答案