我需要使用纯bash脚本从XML文件中获取属性。
So I have the following XML file with a root element Group
and lots of Person
elements, every of them has id
and username
attributes. id
is unique value for each element:
<?xml version="1.0" encoding="UTF-8"?>
<Group id="D_8"
main="false">
<Person id="P_0001"
email="email0001@example.com"
username="person_0001"
password="pass_0001"
active="true"/>
<Person id="P_0002"
email="email0002@example.com"
username="person_0002"
password="pass_0002"
active="true"/>
<!-- ...and hundreds of other Person elements ... -->
</Group>
And I need to use bash script to extract the id
and username
attributes into some key-value structure:
P_0001=person_0001
P_0002=person_0002
检查了其他相关答案,但是大多数建议使用XMLlint之类的XML解析器。但是很遗憾,我没有将它们放在目标计算机上。
请提出如何实现这一目标。