有没有简单的方法将xml文件标签转换为一行?我的XML文件($xml = simplexml_load_file('http://localhost/locations.xml');
)包含:将xml标签合并为一个
<markers>
<marker>
<name>Chipotle Minneapolis</name>
<lat>44.947464</lat>
<lng>-93.320826</lng>
<category>Restaurant</category>
<address>3040 Excelsior Blvd</address>
<address2></address2>
<city>Minneapolis</city>
<state>MN</state>
<postal>55416</postal>
<country>US</country>
<phone>612-922-6662</phone>
<email>[email protected]</email>
<web>http://www.chipotle.com</web>
<hours1>Mon-Sun 11am-10pm</hours1>
<hours2></hours2>
<hours3></hours3>
<featured></featured>
</marker>
</markers>
转换上面的代码格式:
<markers><marker name="Chipotle Minneapolis" lat="44.947464" lng="-93.320826" category="Restaurant" address="3040 Excelsior Blvd" address2="" city="Minneapolis" state="MN" postal="55416" country="US" phone="612-922-6662" email="[email protected]" web="http://www.chipotle.com" hours1="Mon-Sun 11am-10pm" hours2="" hours3="" featured="" features="" /></markers>
感谢
关于'unset($ c [0])'和其他删除元素的方法,请阅读以下内容:[在SimpleXML for PHP中删除具有特定属性的子项](http://stackoverflow.com/questions/262351/remove-a-child-with-a-specific-attribute-in-simplexml-for-php/16062633#16062633) – sidyll
此代码有额外的空间。 – MahdiY