get data from XML using PHP function - php

I currently have an XML file(http://redmine.something.com/projects.xml). I want to read that data to insert into my database using PHP function which I don't know how to write the function to get the data. Below is my example of that XML file structure:
<projects type="array" total_count="7" offset="0" limit="25">
<project>
<id>147</id>
<name>012-003: online shop jakob schlaepfer</name>
<identifier>012-003</identifier>
<created_on>2012-02-01T09:14:29+07:00</created_on>
<updated_on>2012-02-20T10:58:28+07:00</updated_on>
</project>
</projects>
Any link or help would be really appreciated. Thanks.

You're looking for SimpleXML. Here are some basic examples.

Related

Make use of an index file for parsing a large XML file

I'm working on a Wikipedia XML Dump file (15GB), which is provided with an index text file.. looking like this :
1628813:431:Bille August
1628813:434:Blues
1628813:435:Bioéthique
1628813:436:Brive-la-Gaillarde
1628813:438:Burdigala
1628813:439:Bouliac
The XML file is basically in this format:
<page>
<title> </title>
<id> </id>
<revision>
<id> </id>
...
<text> </text>
</revision>
</page>
What I want is to get the Text tag content corresponding to specific page Titles.
How can I make use of the index file for quick parsing/searching to achieve this?
P.S: I already tried many solutions for quick parsing and nothing worked for my needs..
I'm working with PHP, I tried SAX parsing, which is quick but didn't allow me to handle the nodes the way I wanted, and tried combining XMLReader and SimpleXML, but it was too slow..

Edit XML File and Save it from PHP

I need to edit this XML file and update the values, and save to existing XML file.
<resources>
<string name="application">generation</string>
<string name="application2">generation2</string>
<string-type name="type">single</string-type>
</resources>
I need to update the values, 'generation', 'generation2', 'single' from db.
Thanks... hope a quick response. Thanks again.
How to delete child nods??!
You should look into DOMDocument which can parse XML or HTML, modify it and export the modified version back to a string.

Xml Category on product feed

i want to post products to amazon to category of "SportsMemorabilia", using the mws product feed.
i looked over the documentation, it is hard to understand, i also download the xsd to see the xml structure
but still it dosent working.
for this xml is sent (it is only the category part, i also sending all other elements of the product xml..)
<ProductData>
<SportsMemorabilia>
<ProductType>SportsMemorabilia</ProductType>
</SportsMemorabilia>
</ProductData>
it give me this error
<Result>
<MessageID>0</MessageID>
<ResultCode>Error</ResultCode>
<ResultMessageCode>5000</ResultMessageCode>
<ResultDescription>XML Parsing Error at Line 104, Column 26: cvc-complex-type.2.4.b: The content of element 'SportsMemorabilia' is not complete. One of '{AuthenticatedBy}' is expected.</ResultDescription>
</Result>
please, write to me how the xml should look like in order it to work,
thank you.
As per the current version, this is the minimum XML that should pass the published XSD. It doesn't mean it'll work, as functionality built in the service may do additional validation.
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!-- Sample XML generated by QTAssistant (http://www.paschidev.com) -->
<SportsMemorabilia>
<ProductType>SportsMemorabilia</ProductType>
<AuthenticatedBy>AuthenticatedBy1</AuthenticatedBy>
<ConditionProvidedBy>ConditionProvidedBy1</ConditionProvidedBy>
<ConditionRating>ConditionRating1</ConditionRating>
</SportsMemorabilia>
To access the services you need to have an account setup; you have to also fill in the other two elements, at least.
I would strongly suggest you to walk through the document posted here... At least the minimum above should get you over XSD validation errors.

How to update XML file with ajax?

I have xml storage with in this format
<Contacts>
<Contact>
<![CDATA["Some HTML"]]>
</Contact>
<Contact>
<![CDATA["Some HTML"]]>
</Contact>
</Contacts>
I am using XMLHttpRequest to read the data and put it inside a "div" on the page. Now I make some changes on it via JavaScript and I would like to know how can I update the changes made back to the XML file from where I took the data.
I've been googling a lot but I have problems understanding those forums because they are not describing examples similar like mine.
Try using a ajax call which you give the xml data. You can then save the data using simplexml http://nl.php.net/manual/en/book.simplexml.php or using http://nl.php.net/manual/en/book.domxml.php
Leave the "retrieving" your XML on JavaScript, and "saving changes" on PHP. Using jQuery you just $.get() your XML file, and when you save it (let it be .click, .live('click') etc.)
you $.post() strings you wrote in some input to something like save_xml.php. There are some tools for working with XML files in PHP. If you get on well with Smarty, I advise you to keep sort of my_xml_template.tpl , which after smarty->fetch you save in a file with file_put_contents(). Cheers.

What php function can display formated XHTML from a XML file?

Ive been trying to display formatted content blocks from a xml file with no luck. Ive been using simplexml_load_file and other varients which Im now seeing cannot deal with the xhtml tags within the called tag ... eg.
//php contents
<?php $xml=simplexml_load_file("file.xml");
echo ($xml->entry); ?>
//xml contents
<entry>
<p>This does not work</p>
</entry>
whereas
<entry>This works</entry>
can someone please tell me which php function can do this from an xml file and or
what is the best way to display the contents with xhtml formatting?
Im trying to dynamically load content to a webpage without having to build too many pages. I like the idea of having all my content in one xml file for easy edits.
Theres not enough content to justify a database yet.
Thanks in advance
You can try dumping the contents of a certain simplexml node (in this case: $xml->entry) using the asXml function.
echo $xml->entry->asXml();
Check the php documentation on simplexml here (link to the asXml() call):
Simplexml documentation
im getting closer... I found asXML() which outputs the html tags... but not sure yet how to point to specific blocks.... eg $xml->asXML(block) displays 1
got it
$xml->block->asXML()
works
would still like to know if there is a better method tho.

Categories