Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

XML won't validate

Explorer ,
Feb 23, 2009 Feb 23, 2009
Hi folks,

It doesnt like the folling xml, I keep getting the errors:

Can anyone help? I thought the special chars ’ were valid??

Line File name: Nonexistent
2 Column: 23
Error: Can not find declaration of element 'xml'.
Error Position:

<xml version="1.0">



Line File name: Nonexistent
105 Column: 156
Error: Entity "rsquo" was referenced, but not declared.
Error Position:

...ave announced that Sandwell&rsquo;s Agewell

1.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Feb 23, 2009 Feb 23, 2009
Your XML declaration is wrong. You have this:
<xml version="1.0">

It should be this:
<?xml version="1.0" encoding="UTF-8" ?>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 23, 2009 Feb 23, 2009
Thnaks for your reply.

I've changed that but now get the error, any ideas?

Line File name: Nonexistent
2 Column: 7
Error: Processing instruction target matching "[xX][mM][lL]" is not allowed.
Error Position:

<?xml version="1.0" encoding="UTF-8" ?>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Feb 23, 2009 Feb 23, 2009
How are you using this XML? Post the code that is throwing this error, please.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 23, 2009 Feb 23, 2009
Looks like there's funky characters in the title. I'm not sure if that is causing CFs XML parser to get upset.

To play it safe, wrap all your text with a CDATA block.

E.g.:
<title><![CDATA[ this is my title ]]></title>
<summary><![CDATA[ .... ]]></summary>
etc...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 23, 2009 Feb 23, 2009
Sounds to me like you have some whitespace before your XML declaration line. There has to be NO space at all. So make sure you don't have a carriage return or anything like that in your code that's adding space.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 24, 2009 Feb 24, 2009
Thanks for all your help.

I've done your suggestions but still getting problems, code attached
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 24, 2009 Feb 24, 2009
Its throwing this error now:

Line File name: Nonexistent
1 Column: 52
Error: Can not find declaration of element 'items'.
Error Position:

<?xml version="1.0" encoding="ISO-8859-1"?><items>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 24, 2009 Feb 24, 2009
<?xml version="1.0" mencoding="UTF-8" ?>

What's a "memcoding"?

;-)

one of the easiest ways to spot these sort of thngs is to browse to the XML file in a browser. Firefox pointed the exact location of the problem instantly.

--
Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 25, 2009 Feb 25, 2009
Thanks again for your replies folks.

I have this working to an extent, but its very touch and go, its still doesnt like certain charactors.

The xml document is created from a database query, which holds user generated content. Ideally I would like to store the data in the xml document without any formatting, but I need a least paragraph tags.

Can you guys think of a way aorund this?

Is there a way I can store the formatting in xml?

Thanks again

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Feb 25, 2009 Feb 25, 2009
Wrap everything being pulled from the database in an XMLFormat() function. That way, any special characters will be escaped.
http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=functions_t-z_20.html#139554
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Feb 25, 2009 Feb 25, 2009
LATEST
To store your content in XML without formatting use a CDATA section. CDATA can contain any content except "]]>". You will not need to escape XML special characters within a CDATA section. See XML sample attached.

It might also be helpful if you were to provide the CF code you are using to generate your XML file.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources