Skip to content
Advertisement

Tag: simplexml

Remove Namespace from child Element XML PHP

I am trying to create a xml file using simpleXML. This is the output that I need: But this is what I am getting when adding third parameter to the addChild func.: I have tried to leave the third parameter empty like this: $xml->addChild(‘g:id’, 123, ”); but it still adds it like this: <g:id xmlns:g=””>123</g:id> any ideas? Answer SimpleXMLElement::addChild needs

Get values from SimpleXMLElement Object for php array

I need help with this issue, it seems I can’t get targetCurrency out of the SimpleXMLElement Object This outputs: [curr_code] should output ‘EUR’. How can I fix it? Answer You are using the same variable name for two different things: If you were running with display_errors switched on or checking your logs, you would have seen a message like this:

using simple XML (php to change one attribute)

I have an xml input in the form of a string and I want to look at it and find a particular element and modify it. The part of the xml input I’m interested in looks like this and is part of the hierarchy of the in the string the ED element varies so im only interested in identifying all

PHP Split XML based on multiple nodes

I honestly tried to find a solution for php, but a lot of threads sound similar, but are not applicable for me or are for completely different languages. I want to split an xml file based on nodes. Ideally multiple nodes, but of course one is enough and could be applied multiple times. e.g. I want to split this by

Sanitize an external xml file with php

Here’s my problem: Essentially I need to use an XML file from an external source and loop it through to display nicely some data. I created a function that gets content from the external URL (file_get_contents), then I turn the string of XML into an object (I use LIBXML_NOCDATA as a parameter because it contains ), right after I turn

Modify data extracted from rss file with simplexml

I am extracting data from an rss file using simplexml. The urls in are wrong and I am trying to change them. To be able to use the data, I need to strip everything before the word “base” in those urls. I can do it with the following: but its looks messy and I’m pretty sure there is a way

PHP simpleXMLelment xpath returns unexpected results

I have executed the following code on the the sample XML at the bottom of the question and I am getting unexpected results. I would expect this to return only the two record nodes that are children of the current addresses node. But, it actually returns all 5 of the record nodes of the original $xml element. Everything I have

Parsing SimpleXML Object data

How to get “file_url” from this data? Response can contain few objects, and how to parse it? Code that I use: Response: Please help! (don’t ask why I parsing rule34) Answer Hi You can conver it to the array and work with is easy

Advertisement