0

I am currently using xmlhttp send to PUT something back onto the webservice:

My XML :

<collection>
 <beanRepresentation>
  <beanRepId>1323</beanRepId>
  <beanRepName>john</beanRepName>
 </beanRepresentation>

  ...more <beanRepresentations> ..

</collection>

I pull this XML, make some changes using through my HTML page. And now I want to use PUT to update the changes I made to beanRepresenetation.

I do not want to update the whole XML, just the single object I made changes in. I am doing it like the following:

xmlhttp.open("PUT","http://localhost:8080/rest/beanRepresentation",
                                    false);
xmlhttp.setRequestHeader("Content-type","application/xml");
xmlhttp.send((xmlDoc.getElementsByTagName("beanRepresentation")[0]));

firebug says:

PUT http://localhost:8080/rest/beanRepresentation 400 Bad Request

and the Source shows this is what I am sending:

[object Element]

This is the problem, why aren't I sending this back:

<collection>
 <beanRepresentation>
  <beanRepId>1323</beanRepId>
  <beanRepName>Updated Name</beanRepName>
 </beanRepresentation>

</collection>

?? I need it to PUT it back like the above format, not "[Object Element]".

PhoonOne
  • 2,678
  • 12
  • 48
  • 76
  • You pulled this XML and parsed it to JSON, this is why it is represented as [Object Element]. Parse it back to XML and then you should be able to successfully PUT it. Please refer to http://stackoverflow.com/questions/1773550/xml-json-conversion-in-javascript for the conversion between JSON and XML. – snrlx Jan 29 '14 at 18:47
  • You need to get the content from the element e.g. using the outerHTML or outerXML property depending on which DOM you're using... (xmlDoc.getElementsByTagName("beanRepresentation")[0]).outerHTML – dezfowler Jan 29 '14 at 18:52
  • it should be outerXML i assume – PhoonOne Jan 29 '14 at 19:04
  • Depends how you're creating xmlDoc. In the browser the HTML DOM is more widely supported than XML DOM. – dezfowler Jan 29 '14 at 19:25

1 Answers1

0

Figured it out:

xmlhttp.send((new XMLSerializer()).serializeToString(xmlDoc.getElementsByTagName("beanRepresentation")[i]));
PhoonOne
  • 2,678
  • 12
  • 48
  • 76