Jump to content

XML: Help needed on extracting values


ubuntu-user

Recommended Posts

Hello

 

Yesterday I started learning PHPs XML support.

 

I have an XML file I need to update. I've read the file into a variable then run the simplexml_load_string function on it.

 

From there on, I simply extract values as follows:

$name = $xml->name;

 

That works for these:

<name>test</name>

 

However, I'm stuck on how to extract these attributes:

<type first='abc' second='xyz'>standard</type>

 

What I want is the value of "first" and the value of "second".

I can get the first value doing this:

$type_first = $xml->type->attributes();

 

However, I can't find a way of getting a specific value.

 

Does anyone know how to extract these? Also how to update them?

 

With this format:

<name>test</name>

 

I simply run this to change the value:

$xml->name = "New Name";

 

Thank you.

Link to comment
https://forums.phpfreaks.com/topic/183046-xml-help-needed-on-extracting-values/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.