Код для публикации XML из Java в PHP:
URL url = new URL("http://localhost/xml.php"); //your php file on localhost
String document = System.getProperty("user.dir")+"\\<your xml file name>";
FileReader fr = new FileReader(document);
char[] buffer = new char[1024*10];
int bytes_read = 0;
if((bytes_read = fr.read(buffer)) != -1){
URLConnection urlc = url.openConnection();
urlc.setRequestProperty("Content-Type","text/xml");
urlc.setDoOutput(true);
urlc.setDoInput(true);
//Now send xml data to your xml file
PrintWriter pw = new PrintWriter(urlc.getOutputStream());
pw.write(buffer, 0, bytes_read);
pw.close();
//Read response from php file
BufferedReader in = new BufferedReader(new InputStreamReader(urlc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
Подробнее о user.dir
можно прочитать здесь
Код для чтения данных из переданного XML-файла через Java в PHP
<?php
$dataPOST = trim(file_get_contents('php://input'));
$xmlData = simplexml_load_string($dataPOST);
print_r($xmlData);
?>
Подробнее о simplexml_load_string()
здесь
Он просто напечатает XML-данные на веб-странице в качестве ответа.