通过RapidXML获取XML文件的评论

时间:2018-05-05 09:31:44

标签: comments rapidxml

我尝试在xml文件中获取命令的值。我在其手册中找到了函数type()。但它只返回有关节点类型的数字值。有没有办法搞定它?

这是我的代码:

 xml_node<> *Node = Doc.first_node();
 xml_node<> *Sub = Node->first_node("Task");
std::cout << "Comment: " << Sub->type() << std::endl;

价值回报是:评论:1

这是文件的内容:

<!-- \GoogleUpdateTaskMachineCore -->    ***<<== this is the value I wanna get.***
<?xml version="1.0" encoding="UTF-16"?>

<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">

  <RegistrationInfo>

    <Version>1.3.33.7</Version>

    <Description>Keeps your Google software up to date. If this task is disabled or stopped, your Google software will not be kept up to date, meaning security vulnerabilities that may arise cannot be fixed and features may not work. This task uninstalls itself when there is no Google software using it.</Description>

  </RegistrationInfo>

  <Triggers>

    <LogonTrigger>

      <Enabled>true</Enabled>

    </LogonTrigger>

    <CalendarTrigger>

      <StartBoundary>2017-11-14T12:07:01</StartBoundary>

      <ScheduleByDay>

        <DaysInterval>1</DaysInterval>

      </ScheduleByDay>

    </CalendarTrigger>

  </Triggers>

  <Principals>

    <Principal id="Author">

      <UserId>S-1-5-18</UserId>

      <RunLevel>HighestAvailable</RunLevel>

    </Principal>

  </Principals>

  <Settings>

    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>

    <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>

    <StartWhenAvailable>true</StartWhenAvailable>

    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>

    <Enabled>true</Enabled>

    <RunOnlyIfIdle>false</RunOnlyIfIdle>

    <WakeToRun>false</WakeToRun>

    <ExecutionTimeLimit>PT72H</ExecutionTimeLimit>

  </Settings>

  <Actions Context="Author">

    <Exec>

      <Command>C:\Program Files (x86)\Google\Update\GoogleUpdate.exe</Command>

      <Arguments>/c</Arguments>

    </Exec>

  </Actions>

</Task>

1 个答案:

答案 0 :(得分:0)

首先,当您parse_comment_nodes文档时,您需要使用parse()标记。

然后,遍历节点,直到找到具有type() == node_comment的节点,然后获取该节点的value()