all groups > dotnet xml > october 2003 >
You're in the

dotnet xml

group:

WriteProcessingInstruction formatting problem


WriteProcessingInstruction formatting problem Thomas Brodbeck
10/29/2003 1:39:33 AM
dotnet xml:
I have a problem with the
XmlTextWriter.WriteProcessingInstruction method. This
method takes two parameters:

[C#]
public override void WriteProcessingInstruction(
string name,
string text
);

Remarks
If text is either a null reference (Nothing in Visual
Basic) or String.Empty, this method writes a
ProcessingInstruction with no data content, for example <?
name?>.

So i tried to write a processing instruction with the
parameter text set to null. What i got wasn't what i
expected: <?name ?>. This format is not well formed.

Is this a bug or do someone have an advice for correcting
the problem?

Here a small testprogramm:



using System;
using System.IO;
using System.Xml;

public class Sample
{
private const string filename = "testPI.xml";

public static void Main()
{
XmlTextWriter writer = null;

writer = new XmlTextWriter (filename,
null);
//Use indenting for readability.
writer.Formatting = Formatting.Indented;

//Write the XML delcaration.
writer.WriteStartDocument();

//Write the ProcessingInstruction node.
writer.WriteProcessingInstruction("name",
null);

//Write a root element.
writer.WriteStartElement("book");

//Write the genre attribute.
writer.WriteAttributeString
("genre", "novel");

//Write the close tag for the root element.
writer.WriteEndElement();

//Write the XML to file and close the
writer.
writer.Flush();
writer.Close();

//Load the file into an XmlDocument to
ensure well formed XML.
XmlDocument doc = new XmlDocument();
//Preserve white space for readability.
doc.PreserveWhitespace = true;
//Load the file.
doc.Load(filename);

//Display the XML content to the console.
Console.Write(doc.InnerXml);

Console.ReadLine();
}
}
Re: WriteProcessingInstruction formatting problem Oleg Tkachenko
10/29/2003 2:35:03 PM
[quoted text, click to view]

Why do you think so?
According to XML spec,
[16] PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'

so <?name ?> is perfectly well-formed.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel
Re: WriteProcessingInstruction formatting problem anonymous NO[at]SPAM discussions.microsoft.com
10/31/2003 2:31:23 AM
The result is not what is to be expected based on
microsofts documentation which says that the result has to
be <?name?>.

The Problem I have ist that there are parsers which do not
accept the form <?name ?> as wellformed. I opened a
document containing <?name ?> in XMLSpy which treats this
form as not wellformed.


[quoted text, click to view]
Re: WriteProcessingInstruction formatting problem Dimitre Novatchev
10/31/2003 1:28:27 PM
[quoted text, click to view]

Then do not use this product, as it is non-compliant.


=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL


Re: WriteProcessingInstruction formatting problem Oleg Tkachenko
10/31/2003 5:30:44 PM
[quoted text, click to view]

Hmmm, really. Somebody has to report this bug to XML Spy vendor.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel
AddThis Social Bookmark Button