Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / October 2003

Tip: Looking for answers? Try searching our database.

WriteProcessingInstruction formatting problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Thomas Brodbeck - 29 Oct 2003 10:39 GMT
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();
    }
}
Oleg Tkachenko - 29 Oct 2003 13:35 GMT
> 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.

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

so <?name ?> is perfectly well-formed.
Signature

Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

- 31 Oct 2003 11:31 GMT
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.

>-----Original Message-----
>
[quoted text clipped - 7 lines]
>
>so <?name ?> is perfectly well-formed.
Dimitre Novatchev - 31 Oct 2003 13:28 GMT
> 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.

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

=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
Oleg Tkachenko - 31 Oct 2003 16:30 GMT
> 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.

Hmmm, really. Somebody has to report this bug to XML Spy vendor.
Signature

Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.