4
$\begingroup$

When I import url, there will show the folling message:

"Cannot import data as Graph6 format"

The codes as following:

Import["http://pubsonline.informs.org/doi/abs/10.1287/mksc.14.3.G6","XMLObject"]

But the another url will work:

 Import["http://pubsonline.informs.org/doi/abs/10.1287/mksc.14.3.G20","XMLObject"]

I don't know why it happend, I can visit the website directly. I guess the ".G6" is the problem, but I don't know how the solve it.

I change "XMLObject" to "HTML" (by Szabolcs), but the return datas is different with "XMLObject".

enter image description here

$\endgroup$
1
  • $\begingroup$ Note that this is HTML, not XML. Trying to import as XML would fail. $\endgroup$
    – Szabolcs
    Dec 3, 2017 at 12:22

1 Answer 1

4
$\begingroup$

To make this work, you need to specify the format. There is no "XMLObject" format. "XMLObject" is an import element for the "HTML" and "XML" (and perhaps some other) formats. Thus when you only specify "XMLObject", Mathematica is still trying to auto-detect the format. In this case, it will try to import the file as the Graph6 format, which won't work for a HTML document.

Specify the format explicitly as "HTML" and also specify the import element, i.e. that you want the result as an "XMLObjct".

Import["http://pubsonline.informs.org/doi/abs/10.1287/mksc.14.3.G6", {"HTML", "XMLObject"}]

Note that this is exactly the same mistake as using Import["somefile", "Data"], which is unfortunately all too commonly seen on this site. "Data" isn't a format either, and when you use it, you are betting on the success of format detection.

$\endgroup$
6
  • $\begingroup$ Thank you for your answer, I changed the question, and add another url, it will work. I don't know why. $\endgroup$
    – zongxian
    Dec 3, 2017 at 12:36
  • $\begingroup$ @zongxian Because it doesn't end in .g6, so the result of the auto-detection is not the Graph6 format. As I said in the answer, if you leave it up to Mathematica to guess the format, it might or it might not get it right. You are relying on luck. $\endgroup$
    – Szabolcs
    Dec 3, 2017 at 12:40
  • $\begingroup$ I tried your method, but the return contents is different, I will add a image in the question. $\endgroup$
    – zongxian
    Dec 3, 2017 at 12:52
  • $\begingroup$ @zongxian You did not read the answer carefully and did something else than what I suggested. $\endgroup$
    – Szabolcs
    Dec 3, 2017 at 12:58
  • $\begingroup$ I know your mean is there is no "XMLObject", I use it is wrong, but how can I know the website is a "html" or "XML", MMa auto check it and return datas, but if I use "html", it return the different contents with "XMLObject", as I am a new user, so I don't knon how to get the same content as use the wrong parameter of "XMLObject". $\endgroup$
    – zongxian
    Dec 3, 2017 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.