Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to filter XML-elements with attributes in php?

Status
Not open for further replies.

jgu68

Programmer
Feb 7, 2009
2
SE
Hello,
im trying to import xml-data to MySQL.
I only want to import rows without attributes,
like 'aaa,bbb' in the example below.
(I have no problems to import all rows.)

Im using php + DOM XML

<mydoc>
<test>
<text1>aaa</text1>
<text2>bbb</text2>
</test>
<test id="something">
<text1>ccc</text1>
<text2>ddd</text2>
</test>
</mydoc>

All help appreciated!

Regards Jorgen
 
Well I don't know about MySQL, but if I've understood right you're asking for XPath expressions. Check this: For example, for getting all contents into all the text1 labels of the document the XPath expresion would be /mydoc/test/text1/text(). Hope this helps.
 
Thanks!

Was able to solve it after checking out Xpath
using this syntax:

$aaa = $xpath->query("/mydoc/test[not(@id)]");



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top