Skip to content

XML parser returns item from different element in a array #3215

@Erbengi

Description

@Erbengi

Example:

std::stringstream sstream;
sstream << R"(
<array>
  <item>
    <string>foo</string>
    <bool>true</bool>
  </item>
  <item>
    <string>bar</string>
    <bool>false</bool>
    <float>0.4</float>
  </item>
  <item>
    <string>test</string>
    <bool>false</bool>
  </item>
</array>
)";

Poco::XML::InputSource src(sstream);
Poco::XML::DOMParser parser;
auto doc = parser.parse(&src);

auto node = doc->getNodeByPath("/array/item[0]/float");
std::cout << (node ? node->innerText() : "[not found]") << std::endl;

node = doc->getNodeByPath("/array/item[1]/float");
std::cout << (node ? node->innerText() : "[not found]") << std::endl;

node = doc->getNodeByPath("/array/item[2]/float");
std::cout << (node ? node->innerText() : "[not found]") << std::endl;

Output:

0.4
0.4
[not found]

Poco returns float element for item[0] even the first element doesn't contain it. Tested with Poco 1.10.1.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions