Categories
askquestion

Is there anyway to change the content type of an XML document, in the XML document?

Is there anyway to change the content type of an XML document, in the XML document?

Ask Question

Asked
11 years, 1 month ago

Active
10 years, 9 months ago

Viewed
1k times

.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{
margin-bottom:0;
}

0

Is there anyway to change the content-type of an XML document, in the XML document?

I’m working with a really old system that passes back HTML (and we are trying to make it return XML). I’m retrieving it from XMLHttpRequest, and I noticed using netcat that it isn’t passing back any content-type headers.

When I receive the XMLHttpRequest.responseXML, the responseText exists but the responseXML is null.

I’ve already checked the XML being returned to see if it is well formed and it appears to be (it’s a very short document).

xml http-headers xmlhttprequest content-type

share|improve this question

edited May 1 ’09 at 6:52

bignose

21.3k1212 gold badges5959 silver badges9191 bronze badges

asked Dec 19 ’08 at 18:12

leeand00leeand00

21.6k3333 gold badges117117 silver badges248248 bronze badges

What do you mean by content type? MIME, DTD, XSchema, or what?

– Mark Cidade
Dec 19 ’08 at 18:14

The http-headers, Content-type: text/xml or application/xml

– leeand00
Dec 19 ’08 at 18:16

add a comment
 | 

3 Answers
3

active

oldest

votes

1

No. The Content-Type as you refer to it (in the comments to your question) is part of the HTTP headers.

And HTTP is the mere means of transportation for (say) XML documents. They are payload, they know nothing about the HTTP headers, so they can’t change them.

What you probably mean is “Is there an equivalent to <meta http-equiv=”… in XML. No, there is not. Even HTML can’t change the HTTP headers, it can only make the user agent behave differently. This is useful if the HTML file was saved to disk, and upon load no headers are available to the user agent.

In XML, all the necessary information is in the processing instruction (<?xml version=”1.0″ encoding=”UTF-8”?>) at the top of the file. No header info is are needed to load/display it correctly.

share|improve this answer

answered Dec 19 ’08 at 18:19

TomalakTomalak

282k5757 gold badges457457 silver badges566566 bronze badges

add a comment
 | 

0

No.

By the time the UA could get to any such tag, it would already have to have decided what kind of document it’s parsing.

share|improve this answer

answered Dec 19 ’08 at 18:36

GarethGareth

103k3030 gold badges141141 silver badges150150 bronze badges

add a comment
 | 

0

I figured it out, it’s a matter of taking the xhr.responseText string and creating an XML document from it:

function createDOMFromString(sXml){

var browser = navigator.appName;
var oXmlDom = null;

// IE Implementation…
if(browser == “Microsoft Internet Explorer”) {
oXmlDom=new ActiveXObject(“Microsoft.XMLDOM”);
oXmlDom.async=”false”;
oXmlDom.loadXML(sXml);
}
// FF Implementation…
else {
var oParser = new DOMParser();
oXmlDom = oParser.parseFromString(sXml, “text/xml”);
}
// TODO: If we need it Safari implementation.

return oXmlDom;
}

Cheers!

share|improve this answer

answered Dec 19 ’08 at 19:52

leeand00leeand00

21.6k3333 gold badges117117 silver badges248248 bronze badges

Nobody can check his own answer (or everybody would). Honestly, shouldn’t you have asked the question more clearly in the first place? Your edit made all the difference, the question was close to unintelligible in its original state. Please don’t expect your readers to have visionary powers…

– Tomalak
Dec 20 ’08 at 9:51

add a comment
 | 

Your Answer

Thanks for contributing an answer to Stack Overflow!Please be sure to answer the question. Provide details and share your research!But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.

Draft saved
Draft discarded

Sign up or log in

Sign up using Google

Sign up using Facebook

Sign up using Email and Password

Submit

Post as a guest

Name

Email
Required, but never shown

Post Your Answer

Discard

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you’re looking for? Browse other questions tagged xml http-headers xmlhttprequest content-type or ask your own question.

Blog

Podcast: Make my Monolith a Micro

When laziness is efficient: Make the most of your command line

Featured on Meta

TLS 1.0 and TLS 1.1 removal for Stack Exchange services

Did Stack Exchange cut the number of negative comments nearly in half between…

An account of my meeting with the Stack Overflow management team

Related

1252Proper MIME media type for PDF files460How to Deserialize XML document10092What is the correct JSON content type?906What characters do I need to escape in XML documents?960How do I parse XML in Python?984What does <![CDATA[]]> in XML mean?2090How do you parse and process HTML/XML in PHP?3application/xml versus text/xml content types1XMLHttpRequest Object : can’t retrieve data from XML using responseXML

Hot Network Questions

How can I constructively address the fact that a coworker with the same (senior) title doesn’t have the basic skills for the role

How Do I Define Smells I Have Never Experienced?

A Slightly Moth-Eaten Integral Sign

Re-do paint over plaster in bathroom: How to feather/match?

At what point does an aircraft become an airliner?

How to explain that there can only be one magic portal between a planet and another

How does the Contingency spell with Cure Wounds as the contingent spell work with incoming damage?

How to construct a IBM Quantum Experience circuit for the following state transformation?

Is the drug used to stop infection in The Rock real?

What exactly is ALF?

In the UK parliament, how much of Prime Minister’s Questions is pre-planned?

Recovering from stumbling over words

Is there any benefit to partioning hdd data-only disk?

Did Nancy Pelosi say “We’ll have to pass the bill to find out what’s in it”?

What prevents me from setting up an A name entry for “google.ca” to whatever IP I want?

What are the official opposing schools of magic?

Are the stems of rehydrated dried Shiitake usable?

Would all crew leave the ISS if one had a medical emergency?

How do GMs play the man not the board?

What should I (a professor) do if a student keeps answering other students’ questions before I start explaining?

What are these chair-like things in hotels?

Layoffs are coming at my company. I want to volunteer instead of a co-worker. Problem is, I am not supposed to know

Found a co-worker on a dating website. How do I approach them?

Why are two using clauses resolving to the same type seen as ambigious in gcc

more hot questions

Question feed

Subscribe to RSS

Question feed
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

lang-xml

Leave a Reply

Your email address will not be published. Required fields are marked *