Skip to content

Tag: xml

PHP convert XML to JSON

I am trying to convert xml to json in php. If I do a simple convert using simple xml and json_encode none of the attributes in the xml show. $xml = simplexml_load_file(“states.xml”); echo json_encode(…

PHP XML how to output nice format

Here are the codes: If I print it in the browser I don’t get nice XML structure like I just get And I want to be utf-8 How is this all possible to do? Answer You can try to do this: You can make set these parameter right after you’ve created the DOMDocument as well: That’s probably more concise. Output

Creating an XML sitemap with PHP

I’m trying to create a sitemap that will automatically update. I’ve done something similiar with my RSS feed, but this sitemap refuses to work. You can view it live at….

How to use XMLReader in PHP?

I have the following XML file, the file is rather large and i haven’t been able to get simplexml to open and read the file so i’m trying XMLReader with no success in php I’ve unfortunately not found a good tutorial on this for PHP and would love to see how I can get each element content to store in

Accessing @attribute from SimpleXML

I am having a problem accessing the @attribute section of my SimpleXML object. When I var_dump the entire object, I get the correct output, and when I var_dump the rest of the object (the nested tags), I get the correct output, but when I follow the docs and var_dump $xml->OFFICE->{‘@attributes’}, I get an empty object, despite the fact that the

Is there a way to get all of a DOMElement’s attributes?

I’m reading some XML with PHP and currently using the DOMDocument class to do so. I need a way to grab the names and values of a tag’s (instance of DOMElement) attributes, without knowing beforehand what any of them are. The documentation doesn’t seem to offer anything like this. I know that I can get an attribute’s value if I