Questions tagged [xml-declaration]

An XML declaration (e.g: ) specifies the XML version and encoding of an XML document. It is optional for XML 1.0 version and UTF-8 encoding.

An XML declaration specifies the XML version and encoding of an XML document. It resembles a processing instruction but is technically not one. Here is an example of an XML declaration with the default values for version and encoding:

<?xml version="1.0" encoding="UTF-8" ?>

Only one XML declaration is allowed in an XML document, and it if one does appear, it may only be at the very top of the document.

50 questions
135
votes
3 answers

Does a valid XML file require an XML declaration?

I am parsing an XML file using Sax Parser of Xerces. Is the XML declaration required?
eros
  • 4,946
  • 18
  • 53
  • 78
125
votes
5 answers

Meaning of -

I am new to XML and I am trying to understand the basics. I read the line below in "Learning XML", but it is still not clear, for me. Can someone point me to a book or website which explains these basics clearly? From Learning XML: The XML…
XML Boy
  • 1,363
  • 2
  • 9
  • 9
114
votes
4 answers

How can I make the xmlserializer only serialize plain xml?

I need to get plain xml, without the at the beginning and xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" in first element from XmlSerializer. How can I do…
Grzenio
  • 35,875
  • 47
  • 158
  • 240
38
votes
2 answers

SVG in HTML5 – when is XML declaration `` needed?

When using SVG within HTML5: Is the XML declaration needed with SVG as images via or as CSS background-images? This is slightly related to “Are SVG parameters such as 'xmlns' and 'version' needed”. The…
Volker E.
  • 5,911
  • 11
  • 47
  • 64
32
votes
4 answers

OK to put comments before the XML declaration?

Is it OK to put comments before the XML declaration in an XML file?
sourcenouveau
  • 29,356
  • 35
  • 146
  • 243
27
votes
1 answer

How to prevent XDocument from adding XML version and encoding information

Despite using the SaveOptions.DisableFormatting option in the following code: XDocument xmlDoc = XDocument.Load(FileManager.SourceFile); string element="campaign"; string attribute="id"; var items = from item in xmlDoc.Descendants(element) …
Ein Doofus
  • 495
  • 1
  • 5
  • 12
18
votes
2 answers

Preserving original doctype and declaration of an lxml.etree parsed xml

I'm using python's lxml and I'm trying to read an xml document, modify and write it back but the original doctype and xml declaration disappears. I'm wondering if there's an easy way of putting it back in whether through lxml or some other solution?
incognito2
  • 1,024
  • 3
  • 13
  • 20
6
votes
1 answer

Are multiple XML declarations in a document well-formed XML?

Is having two XML declarations in the same document well-formed XML? hello I believe it is not, however I can't find a source to back me up on…
Mike
  • 58,961
  • 76
  • 175
  • 221
4
votes
5 answers

Reading contents of XML file without having to remove the XML declaration

I want to read all XML contents from a file. The code below only works when the XML declaration () is removed. What is the best way to read the file without removing the XML declaration? XmlTextReader reader =…
Pingpong
  • 7,681
  • 21
  • 83
  • 209
4
votes
1 answer

Add XML declaration to XML document programmatically

I want to add the declaration to an XML document generated in Javascript, but I did not find sufficient documentation. Let's say I want to create programmatically (using Javascript) the following XML document:
JacopoStanchi
  • 1,962
  • 5
  • 33
  • 61
4
votes
2 answers

SQL Server FOR XML PATH: Set xml-declaration or processing instruction "xml-stylesheet" on top

I want to set a processing instruction to include a stylesheet on top of an XML: The same issue was with the xml-declaration (e.g. ) Desired result:
Shnugo
  • 66,100
  • 9
  • 53
  • 114
3
votes
1 answer

How do I get rid of the xmlns declarations inserted by the XmlSerializer?

I have this type: [Serializable, DataContract] public class A { [DataMember(Order = 1)] public int P1 { get; set; } [DataMember(Order = 2)] public XmlSerializableDictionary P2 { get; set; } } Where XmlSerializableDictionary…
mark
  • 59,016
  • 79
  • 296
  • 580
3
votes
1 answer

How to add "standalone="yes" to XML declaration using xml.etree.ElementTree

I've tried looking at other questions similar to this, but none seem to answer for xml.etree.ElementTree. Currently my code looks like this (it's just a simple XML generator) import xml.etree.ElementTree as…
Golopogus
  • 41
  • 1
  • 2
3
votes
1 answer

Checking if XML declaration is present

I am trying to check whether an xml file contains the necessary xml declaration ("header"), let's say: ...rest of xml file... I am using xml ElementTree for reading and getting info out of the file, but it…
Dennis Vymer
  • 119
  • 1
  • 1
  • 9
3
votes
2 answers

Why rather than for XHTML?

In the beginning of an XHTML file, why do we use "xml" in the following construct: Shouldn't it be:
user5608145
1
2 3 4