這是我的示例xml文件。我如何獲得每個元素,屬性和它們的值。我想要所有版本的代碼和名稱,所有版本的代碼和名稱以及所有品牌的代碼和名稱?如何從xml獲取元素,屬性及其值?
<?xml version="1.0" encoding="UTF-8"?>
<PLM_University namespace="DS">
<ALL_VERSIONS>
<version code="1" name="V1" description="Version for CLS Products">
<RELEASES_LIST>
<release code="7" name=".7" rank="5" description="">
<BRAND_LIST>
<BRAND code="WLS" name="Companion">
<SOLUTIONS_LIST>
<SOLUTION code="WLS_STU" name="Companion Learning Space" />
</SOLUTIONS_LIST>
</BRAND>
</BRAND_LIST>
</release>
</RELEASES_LIST>
</version>
<version code="10" name="Matrix10" description="Version for Matrix Products">
<RELEASES_LIST>
<release code="6" name=".6" rank="1" description="">
<BRAND_LIST>
<BRAND code="ENOVIA" name="ENOVIA Collaborative Innovation">
<SOLUTIONS_LIST>
<SOLUTION code="ENOV_MX1" name="ENOVIA MatrixOne" />
</SOLUTIONS_LIST>
</BRAND>
</BRAND_LIST>
</release>
<release code="7" name=".7" rank="2" description="">
<BRAND_LIST>
<BRAND code="ENOVIA" name="ENOVIA Collaborative Innovation">
<SOLUTIONS_LIST>
<SOLUTION code="ENOV_MX1" name="ENOVIA MatrixOne" />
</SOLUTIONS_LIST>
</BRAND>
</BRAND_LIST>
</release>
<release code="8" name=".8" rank="3" description="">
<BRAND_LIST>
<BRAND code="ENOVIA" name="ENOVIA Collaborative Innovation">
<SOLUTIONS_LIST>
<SOLUTION code="ENOV_MX1" name="ENOVIA MatrixOne" />
</SOLUTIONS_LIST>
</BRAND>
</BRAND_LIST>
</release>
</RELEASES_LIST>
</version>
</ALL_VERSIONS>
</PLM_University>
我使用的文件,而不是字符串。你能否告訴我其他方式來做到這一點? – Alpa 2013-02-12 05:34:04
@Alpa你可以使用fopen和fread從file.see中創建一個字符串。更改答案 – 2013-02-12 05:38:08
@mohammadmohsenipur你不需要構建$ xml字符串,你可以簡單地使用'$ doc-> load('1.xml'); – 2013-02-12 05:40:25