我正在尝试使用 tiny xml 解析器解析以下 xml。我正在尝试获取 xml 文件中 q2channel 标记的所有生产者和消费者属性的值。我正在使用 tinyxml2。
到目前为止,我已经编写了以下代码,但我被困在这里,因为当我尝试打印一些我得到空的东西时。
XMLDocument doc;
bool loadOkay=doc.LoadFile( "resources/q2profiling.xml" );
XMLElement* titleElement = doc.FirstChildElement()->FirstChildElement();
const char* title = titleElement->GetText();
printf( "The remaining xml is %s\n", title );
我已经尝试了几种不同的代码变体来推进我的工作,但我被困在这里。请帮助我从 xml 打印 q2channel 标记的所有消费者和生产者属性的值。
xml文件如下所示
<
?xml version="1.0" encoding="UTF-8" ?>
<q2:profiles xmlns:q2="http://www.example.org/q2profiling" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.org/q2profiling q2profiling.xsd">
<q2:application name="testAPPlication">
<q2:QDUGraph>
<q2:channel producer="UNKNOWN_PRODUCER(CONSTANT_DATA)" consumer="Out_of_the_main_function_scope">
<q2:UnMA>19298</q2:UnMA>
<q2:Bytes>25892</q2:Bytes>
<q2:UnDV>19298</q2:UnDV>
<q2:UnMARanges>
<q2:range lower="134512692" upper="134512695" />
<q2:range lower="134512700" upper="134512703" />
</q2:UnMARanges>
</q2:channel>
<q2:channel producer="UNKNOWN_PRODUCER(CONSTANT_DATA)" consumer="main">
<q2:UnMA>160</q2:UnMA>
<q2:Bytes>234</q2:Bytes>
<q2:UnDV>160</q2:UnDV>
<q2:UnMARanges>
<q2:range lower="134513084" upper="134513087" />
<q2:range lower="134513116" upper="134513119" />
<q2:range lower="134513129" upper="134513129" />
</q2:UnMARanges>
</q2:channel>
<q2:channel producer="Out_of_the_main_function_scope" consumer="Out_of_the_main_function_scope">
<q2:UnMA>1474</q2:UnMA>
<q2:Bytes>14815</q2:Bytes>
<q2:UnDV>2468</q2:UnDV>
<q2:UnMARanges>
<q2:range lower="134520828" upper="134520831" />
<q2:range lower="134520836" upper="134520843" />
<q2:range lower="3077693172" upper="3077693175" />
</q2:UnMARanges>
</q2:channel>
<q2:channel producer="Out_of_the_main_function_scope" consumer="main">
<q2:UnMA>209</q2:UnMA>
<q2:Bytes>381</q2:Bytes>
<q2:UnDV>209</q2:UnDV>
<q2:UnMARanges>
<q2:range lower="134520836" upper="134520847" />
<q2:range lower="3045611784" upper="3045611795" />
</q2:UnMARanges>
</q2:channel>
<q2:channel producer="main" consumer="Out_of_the_main_function_scope">
<q2:UnMA>40</q2:UnMA>
<q2:Bytes>60</q2:Bytes>
<q2:UnDV>40</q2:UnDV>
<q2:UnMARanges>
<q2:range lower="3048639008" upper="3048639019" />
<q2:range lower="3048639024" upper="3048639031" />
</q2:UnMARanges>
</q2:channel>
<q2:channel producer="main" consumer="main">
<q2:UnMA>32</q2:UnMA>
<q2:Bytes>444</q2:Bytes>
<q2:UnDV>88</q2:UnDV>
<q2:UnMARanges>
<q2:range lower="3048639008" upper="3048639011" />
<q2:range lower="3048639016" upper="3048639019" />
</q2:UnMARanges>
</q2:channel>
<q2:channel producer="UNKNOWN_PRODUCER(CONSTANT_DATA)" consumer="sum">
<q2:UnMA>1</q2:UnMA>
<q2:Bytes>1000</q2:Bytes>
<q2:UnDV>1</q2:UnDV>
<q2:UnMARanges>
<q2:range lower="134520860" upper="134520860" />
</q2:UnMARanges>
</q2:channel>
<q2:channel producer="UNKNOWN_PRODUCER(CONSTANT_DATA)" consumer="diff">
<q2:UnMA>1</q2:UnMA>
<q2:Bytes>1000</q2:Bytes>
<q2:UnDV>1</q2:UnDV>
<q2:UnMARanges>
<q2:range lower="134520860" upper="134520860" />
</q2:UnMARanges>
</q2:channel>
<q2:channel producer="init" consumer="sum">
<q2:UnMA>2000</q2:UnMA>
<q2:Bytes>2000</q2:Bytes>
<q2:UnDV>2000</q2:UnDV>
<q2:UnMARanges>
<q2:range lower="134520896" upper="134521895" />
<q2:range lower="134523968" upper="134524967" />
</q2:UnMARanges>
</q2:channel>
<q2:channel producer="init" consumer="diff">
<q2:UnMA>2000</q2:UnMA>
<q2:Bytes>2000</q2:Bytes>
<q2:UnDV>2000</q2:UnDV>
<q2:UnMARanges>
<q2:range lower="134520896" upper="134521895" />
<q2:range lower="134523968" upper="134524967" />
</q2:UnMARanges>
</q2:channel>
</q2:QDUGraph>
</q2:application>
</q2:profiles>