I've successfully saved down this XML file to my server using the following PHP:
file_put_contents("test.xml", fopen("http://www.treasury.gov/resource-center/data-chart-center/interest-rates/pages/XmlView.aspx?data=yieldyear&year=2015", 'r'));
Now i'm trying to get it into my DB. Just trying to get it to work by executing SQL in the phpMyAdmin GUI. I successfully setup the following table:
CREATE TABLE `test` (
`NEW_DATE` varchar(40) NOT NULL,
`BC_1MONTH` int(11) NULL,
`BC_3MONTH` int(11) NULL,
PRIMARY KEY (`NEW_DATE`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
The following code runs without error, but just results in the addition of one empty row to my DB.
LOAD XML LOCAL INFILE 'test.xml'
INTO TABLE test
ROWS IDENTIFIED BY '<content>';
I see here that MySQL server looks for field names matching the column names of the target table. It is also mentioned that there is no requirement for every field in the XML file be matched with a column in the corresponding table. Fields which have no corresponding columns are skipped. Are my column names not matching the XML because of the XML prefixes and namespaces or am I barking up the wrong tree?
This question shows how to reference the same XML elements using PHP. Apparently prefix definition is required using registerXPathNamespace()
in order to build an Xpath:
Do I need to build such an Xpath in SQL?
Perhaps I could remove the namespace/prefix data in PHP when I save the XML down using something like LIBXML_NSCLEAN; apparently this removes redundant namespace declarations. What qualifies as redundant?
Another option for removing namespaces seems to be XSL stylesheets. Per this question.
What is the best approach to solving this issue?