Some very basic xml

T

Tony Johansson

Hello!

I know this might not be the appropriate forum for xml question.
But xml is so important for .NET I hope my basic question can be answered in
this forum.

I just wonder does every xml document have a XSD schema or XDR schema ?
Is it possible to say that the purpose for schema is to have a definition
for syntax.

Or can anyone else give a basic explanation what schema is used for in .NET.

//Tony
 
P

Pavel Minaev

I just wonder does every xml document have a XSD schema or XDR schema ?

No. Aside from the fact that there are many other ways to define an
XML schema (e.g. old-fashioned DTDs, or RELAX NG), a document can have
no schema at all.
Is it possible to say that the purpose for schema is to have a definition
for syntax.

XML schema does not define the syntax - it defines the structure of
the document, in terms of XML infoset. In case of W3C XML Schema
(XSD), it can also augment the infoset of the document with things
such as types, and default values for missing attributes and elements.
Or can anyone else give a basic explanation what schema is used for in .NET.

On the most basic level, to validate XML input and output against it.
There's also the aforementioned XML infoset augmentation - for
example, if you read an XML document with an associated schema into an
instance of XmlDocument with validation enabled, and the schema
defines some attributes with default values, those attributes will be
present in XmlDocument even if they were absent in the original XML,
and will have the default values as specified. In addition to that,
every element is associated with the corresponding type in the XSD
schema, and that type information can also be queried via .NET XML
APIs, and used as needed (and, of course, xsi:type attribute can be
used to explicitly specify types of elements in source XML).
 
T

Tony Johansson

Hello!

One more question about xml.
I read in a book about basic xml and it says.
"An XML document could be a physical file on your computer or just a string
in memory."

The first part of the above sentence is normal that an xml document is a
physical file on disk.
But what does it mean when it says that it could be just a string in memory
?

//Tony



"Pavel Minaev" <[email protected]> skrev i meddelandet
I just wonder does every xml document have a XSD schema or XDR schema ?

No. Aside from the fact that there are many other ways to define an
XML schema (e.g. old-fashioned DTDs, or RELAX NG), a document can have
no schema at all.
Is it possible to say that the purpose for schema is to have a definition
for syntax.

XML schema does not define the syntax - it defines the structure of
the document, in terms of XML infoset. In case of W3C XML Schema
(XSD), it can also augment the infoset of the document with things
such as types, and default values for missing attributes and elements.
Or can anyone else give a basic explanation what schema is used for in
..NET.

On the most basic level, to validate XML input and output against it.
There's also the aforementioned XML infoset augmentation - for
example, if you read an XML document with an associated schema into an
instance of XmlDocument with validation enabled, and the schema
defines some attributes with default values, those attributes will be
present in XmlDocument even if they were absent in the original XML,
and will have the default values as specified. In addition to that,
every element is associated with the corresponding type in the XSD
schema, and that type information can also be queried via .NET XML
APIs, and used as needed (and, of course, xsi:type attribute can be
used to explicitly specify types of elements in source XML).
 
J

Jon Skeet [C# MVP]

One more question about xml.
I read in a book about basic xml and it says.
"An XML document could be a physical file on your computer or just a string
in memory."

The first part of the above sentence is normal that an xml document is a
physical file on disk.
But what does it mean when it says that it could be just a string in memory
?

It means that:

string xml = "<?xml version='1.0' encoding='UTF-8' ?><root><element
attr='value' /></root>";

is a perfectly valid XML document. It's just data.

Jon
 
P

Pavel Minaev

Tony said:
Hello!

One more question about xml.
I read in a book about basic xml and it says.
"An XML document could be a physical file on your computer or just a string
in memory."

The first part of the above sentence is normal that an xml document is a
physical file on disk.
But what does it mean when it says that it could be just a string in memory

To quote the W3C XML spec (http://www.w3.org/TR/xml/#sec-documents):

Definition: A data object is an XML document if it is well-formed,
as defined in this specification.
Definition: A textual object is a well-formed XML document if:

1. Taken as a whole, it matches the production labeled document.
2. It meets all the well-formedness constraints given in this
specification.
3. Each of the parsed entities which is referenced directly or
indirectly within the document is well-formed.

Note that this specifically refers to some abstract "textual objects",
and not files. A "textual object" can be a string in memory, a field
in the database (SQL Server has XML data type for fields, for
example), an output of a program to stdout, an HTTP Web service
responce, etc. So long as it has textual representation which matches
the XML grammar, it is XML.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top