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 / Languages / C# / January 2008

Tip: Looking for answers? Try searching our database.

Making an XML mess, oh.. message

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
christery@gmail.com - 26 Jan 2008 22:46 GMT
Trying (or has accompished) a XML message by instanitated a class and
fed it to the xmlwriter, now the receiver dont like my (MS?) XML and
want me to code it by hand... *mumbles*
Can I edit a class with some [mumbojumbo] to enter xml handles as I
please or?
put the root declaration with that, but namespace and objectid is
inherited from my code... They (consultant) build it from scratch just
like a string and send it... but I dont see the point, im sending a
instanceiated object (that cant be spelld right) so I do it this way,
if I change the class the message will change automaticly ->less 4 me
to worry about..

Wish I could post the code, but not at work so... just bugging me that
I cant solve it nicely..
//CY
Arne Vajhøj - 27 Jan 2008 02:38 GMT
> Trying (or has accompished) a XML message by instanitated a class and
> fed it to the xmlwriter, now the receiver dont like my (MS?) XML and
[quoted text clipped - 7 lines]
> if I change the class the message will change automaticly ->less 4 me
> to worry about..

Could you give an example of:
  - class
  - XML you get
  - XML you want
?

Arne
christery@gmail.com - 27 Jan 2008 10:42 GMT
> christ...@gmail.com wrote:
> > Trying (or has accompished) a XML message by instanitated a class and
[quoted text clipped - 16 lines]
>
> Arne

So, they want something like:

<?xml version="1.0" standalone="yes"?>
<MESSAGE>
    <HEADER>
        <Identity>633361405884157414</Identity>
        <Sender>TRANSPONDERSYSTEMET</Sender>
        <Reciever>LUPP</Reciever>
        <Type>VAGNDATA</Type>
        <Test>N</Test>
    </HEADER>
    <VAGNDATA>
        <TaggId>00059F</TaggId>
         <VagnAgare>0837</VagnAgare>
         <VagnsNummer>447217154</VagnsNummer>
         <VagnSida>H</VagnSida>
         <RSSI>0007</RSSI>
         <TidPunkt>2008010808:2248</TidPunkt>
    </VAGNDATA>
</MESSAGE>

And what (not nearly completed) I send look like
<?xml version="1.0" encoding="utf-8"?><vagn xmlns:xsi="http://
www.w3.org/2001/X
MLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="JvgAdjToL upp"><RSSI>1234</RSSI><vagnId>3245</vagnId></vagn>

Thinking along the lines of using for example:

using System;
using System.Xml.Serialization;

namespace Console_Test
{
   [XmlRootAttribute(Namespace = "JvgAdjToLupp", IsNullable =
false)]
   public class vagn
   {
       private string _RSSI;
       private string _vagnId;

       public String RSSI
       {
           get { return _RSSI; }
           set { _RSSI = value; }
       }

       public String vagnId
       {
           get { return _vagnId; }
           set { _vagnId = value; }
       }
   }
}

yes I know its not the same (not even close, but I didnt have the code
with me) but just the first line standalone=yes... where in *el* did
that come from?

//CY
Marc Gravell - 27 Jan 2008 21:02 GMT
Here's a useful trick for you; put your desired xml in a file,
test.xml.

Now load the VS command prompt (in the start menu) and execute (note
you might need to specify the path):

===
xsd test.xml
xsd test.xsd /classes
===

The first line creates test.xsd from your test.xml; the second line
creates test.cs from your test.xsd; this gives you an example of how
you can generate the desired output with attributes (heck, you could
just use this test.cs "as is") - for example:


[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
   public string Identity {
       get {
           return this.identityField;
       }
       set {
           this.identityField = value;
       }
   }

If you want to change the markup at the start of the xml (or the
spacing etc), you can do this via XmlWriterSettings - for example:

           XmlWriterSettings settings = new XmlWriterSettings();
           settings.OmitXmlDeclaration = true;
           using(XmlWriter writer = XmlWriter.Create(path, settings))
{
               serializer.Serialize(writer, obj);
               writer.Close();
           }

Marc
christery@gmail.com - 29 Jan 2008 17:58 GMT
> Here's a useful trick for you; put your desired xml in a file,
> test.xml.
[quoted text clipped - 6 lines]
> xsd test.xsd /classes
> ===

OK, I just serialized the instance of the class into xml something
like this example:

           String XmlizedString = null;
           MemoryStream memoryStream = new MemoryStream ( );
           XmlSerializer xs = new XmlSerializer ( typeof
( Animal ) );
           XmlTextWriter xmlTextWriter = new XmlTextWriter
( memoryStream, Encoding.UTF8 );

           xs.Serialize ( xmlTextWriter, pObject );
           memoryStream = ( MemoryStream ) xmlTextWriter.BaseStream;
           XmlizedString = UTF8ByteArrayToString
( memoryStream.ToArray ( ) );

But I had to loose the double UTF8 encoding... got some strange char
in the beginning..
This just get pObject and write it to a memorystream but i lose a bit
of control, its just the instance of the class that is XML coded

Your way might be better, then I have control over produced code  via
the definition xsd
//CY

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.