Re: Really basic newbie question

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Dino Chiesa [Microsoft] (dinoch_at_online.microsoft.com)
Date: 06/16/04


Date: Tue, 15 Jun 2004 20:05:53 -0400


"Mark Rae" <mark@mark-N-O-S-P-A-M-rae.co.uk> wrote in message
news:%23aVyii7TEHA.3988@TK2MSFTNGP10.phx.gbl...

> The above doesn't cause any errors, and pretty much works as I expect,
apart
> from the format of the output. It displays as follows:
>
> <?xml version="1.0" encoding="utf-8" ?>
> <string xmlns="http://www.markrae.co.uk/"><?xml version="1.0"
> encoding="utf-8"?> <!--This is a comment--> <Return> <Postcode>AB1
> 1BB</Postcode> <ReturnValue>1</ReturnValue> </Return></string>
>
> whereas I'd expect it to display as:
>
> <?xml version="1.0" encoding="utf-8" ?>
> <string xmlns="http://www.markrae.co.uk/"></string>
> <!--This is a comment-->
> <Return>
> <Postcode>AB1 1BB</Postcode>
> <ReturnValue>1</ReturnValue>
> </Return>
>

>From what point in the code are you displaying it? and to what output
stream (or device)?
When I try it, by printing it right after I call that routine, it displays
the way you expect.

> I'm sure I'm missing something completely obvious!
>
> Any assistance gratefully received.

Ok, then
you didn't ask but,
I would suggest you do not serialize your data into xml and then stuff it
into a string. No point in doing that. You have to wade through all the
XML writing nonsense, and it's just too much work.

Rather than use XmlTextWriter to format an XML doc and then write it into a
memory stream and read it into a string....
Just fill an object and return the object. All the XML is done
automatically for you.

example:
//-------code begins----------------------------------------
namespace Validation
{

  [System.Xml.Serialization.XmlRoot("Return")]
  public class PostCodeValidation_Type
  {
    public string Postcode;
    public int ReturnValue;
  }

  public class CValidation2
  {

    public PostCodeValidation_Type ValidateUKPostCode(string input) {
      PostCodeValidation_Type r = new PostCodeValidation_Type();
      r.Postcode= input;
      r.ReturnValue= 1;
      return r;
    }

    public static void Main() {
      try {
        CValidation2 me = new CValidation2();

        PostCodeValidation_Type t= me.ValidateUKPostCode("VeryNice");

        // --
        // this is just for display purposes.
        // if used within a webservice, the PostCodeValidation_Type
would be implicitly serialized when you return it.
        System.Console.WriteLine("\nVersion2:");
        System.Xml.Serialization.XmlSerializer s= new
System.Xml.Serialization.XmlSerializer(typeof(PostCodeValidation_Type));
        System.Xml.Serialization.XmlSerializerNamespaces ns = new
System.Xml.Serialization.XmlSerializerNamespaces();
        ns.Add( "", "" );
        s.Serialize(System.Console.Out, t, ns);
        System.Console.WriteLine("\n");
        // end display logic
        // --
      }
      catch (System.Exception e1){
        System.Console.WriteLine("Exception: \n" + e1);
      }
    }
  }
}

//-------code ends----------------------------------------

>
> Best regards,
>
> Mark Rae
>
>



Relevant Pages

  • Re: Data table text I/O package?
    ... regular and homogenuous data in mind. ... Given a data format much like in, ... I said XML is good for parsing of data if you cannot tell in advance that the data stream is totally free of errors. ... However, if some data item contains a separator due to an error, you loose the whole stream, or use the wrong data without noticing this, in the worst case. ...
    (comp.lang.ada)
  • Re: Help with System.IO.Stream
    ... A stream just contains a sequence of bytes, it has nothing to do with XML. ... XML is simply the format of those bytes. ... > How can/should I pass this XML string via a stream to a method such as ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Sane Syntax
    ... vital role in the future of TeX but we need some more human friendly ... Generating well formed LaTeX2e documents from XML ... Another approach is to convert existing documents to XML format and go ... TEI, together with DocBook, are the two ...
    (comp.text.tex)
  • Re: XHTML vs HTML
    ... to be the predominant type of HTML used on the web for many years yet. ... First, it is XML. ... XHTML is also ... transformed using XSL from and into virtually *any* other data format. ...
    (microsoft.public.frontpage.programming)
  • Re: text to bibliography?
    ... to xml: you can store binary data in an xml file. ... including your well-formattedbibliography(no longer in xml format). ... It is in annotated bibliographies (something Word 2007 does not ... that %I is actually the field representing the publisher. ...
    (microsoft.public.word.docmanagement)