PHP SIMPLEXML GET NODE/ATTRIBUTE VALUES MAIN TIPS

  • SimpleXML is an extension of PHP, allowing us to access and work with XML data.
  • Using SimpleXML, you can treat XML documents as data structure you can use like arrays or objects.
  • You can access Node and Attribute values using SimpleXML.
  • PHP SIMPLEXML GET NODE/ATTRIBUTE VALUES EXAMPLE XML FILE

    Let’s have a look at one of our XML documents, which is called “bookstore.xml”:

    Example -

    PHP SIMPLEXML GET NODE/ATTRIBUTE VALUES NODE VALUE FROM SPECIFIC ELEMENT

    This code example acquires the values of elements of the first two books in the “books.xml” file:

    Example -

    PHP SIMPLEXML GET NODE/ATTRIBUTE VALUES NODE VALUE LOOP

    This code example iterates through every element from our “books.xml” document, getting the node value each element inside the elements:

    Example -

    PHP SIMPLEXML GET NODE/ATTRIBUTE VALUES SPECIFIC ATTRIBUTE VALUES

    This code example acquries the “category” attribute value from firs element it finds and then the “lang” attribute’s value from the element from the second

    Example -