在perl中获取XML树数据(Getting at XML tree data in perl)

我需要使用perl解析XML文件,我可以使用XML :: Simple模块加载文件,但在XML树中有一个我无法使用DataDumper模块看到的标记,但我可以看到它的值。

<testcase id="10"> . . . </testcase>

以上是带有testcase标记的XML文件的示例。 这是我遇到困难的部分。 使用DataDumper查看数组的内容我看到如下所示:

$VAR1 = { 'testcases' => { 'file' => 'testcases.xml', 'testcase' => { '10' => { },

既然定义了XML,为什么它不包含在包含id的VAR1数组中呢? 而不是期望testcases-> testcase-> id我得到testcases-> testcase-> 10。 哪个10是id,但'id'标签发生了什么?

I need to parse an XML file using perl which I can load the file using the XML::Simple module but within the XML tree there is a tag that I can't see using the DataDumper module but I can see it's value instead.

<testcase id="10"> . . . </testcase>

Above is a Sample of the XML file with the testcase tag. It's the part that I have difficulty with. Using DataDumper to view the contents of the array I see something like this:

$VAR1 = { 'testcases' => { 'file' => 'testcases.xml', 'testcase' => { '10' => { },

Since the XML is defined like why isn't it layed out in the VAR1 array with the id included? Instead of expecting testcases->testcase->id I get testcases->testcase->10. Which 10 is the id but what happened to the 'id' tag?

最满意答案

那是因为默认配置包括

KeyAttr => [qw( name key id )]

指定

KeyAttr => []

将导致id与任何其他属性没有区别。

That's because the default config includes

KeyAttr => [qw( name key id )]

Specifying

KeyAttr => []

will cause id to be no different than any other attribute.

在perl中获取XML树数据(Getting at XML tree data in perl)

我需要使用perl解析XML文件,我可以使用XML :: Simple模块加载文件,但在XML树中有一个我无法使用DataDumper模块看到的标记,但我可以看到它的值。

<testcase id="10"> . . . </testcase>

以上是带有testcase标记的XML文件的示例。 这是我遇到困难的部分。 使用DataDumper查看数组的内容我看到如下所示:

$VAR1 = { 'testcases' => { 'file' => 'testcases.xml', 'testcase' => { '10' => { },

既然定义了XML,为什么它不包含在包含id的VAR1数组中呢? 而不是期望testcases-> testcase-> id我得到testcases-> testcase-> 10。 哪个10是id,但'id'标签发生了什么?

I need to parse an XML file using perl which I can load the file using the XML::Simple module but within the XML tree there is a tag that I can't see using the DataDumper module but I can see it's value instead.

<testcase id="10"> . . . </testcase>

Above is a Sample of the XML file with the testcase tag. It's the part that I have difficulty with. Using DataDumper to view the contents of the array I see something like this:

$VAR1 = { 'testcases' => { 'file' => 'testcases.xml', 'testcase' => { '10' => { },

Since the XML is defined like why isn't it layed out in the VAR1 array with the id included? Instead of expecting testcases->testcase->id I get testcases->testcase->10. Which 10 is the id but what happened to the 'id' tag?

最满意答案

那是因为默认配置包括

KeyAttr => [qw( name key id )]

指定

KeyAttr => []

将导致id与任何其他属性没有区别。

That's because the default config includes

KeyAttr => [qw( name key id )]

Specifying

KeyAttr => []

will cause id to be no different than any other attribute.