Results 1 to 10 of 10

Thread: how to write a xml file with the following format?

  1. #1

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729

    how to write a xml file with the following format?

    <?xml version="1.0" encoding="windows-1252" standalone="yes"?>
    <DCPlusPlus>
    <Settings>
    <Connection type="string">Cable</Connection>
    <DownloadDirectory type="string">G:\DOWNLOADS\DC++\</DownloadDirectory>
    <Nick type="string">Iniquity</Nick>
    </Settings>
    <Share>
    <Directory>G:\metal albuns</Directory>
    <Directory>G:\mp3</Directory>
    </Share>
    </DCPlusPlus>
    How can I do it? With which classes?
    \m/\m/

  2. #2
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704

  3. #3
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Something cool you can do is to build a xsd (schema) of that xml. Then you can use the xsd.exe tool to generate classes based off the schema and you then have a class that you can fill the properties of, then serialize to that xml. I just discovered the xsd.exe tool, and I am falling in love with it. I can do so much with it now that I am finding uses everywhere.

  4. #4
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Don't get drunk with the stuff man... the hangover might kill ya

    Take it slow...

  5. #5

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    what does this mean?
    w.WriteAttributeString("xmlns", "x", null, "urn:1");
    \m/\m/

  6. #6
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    You don't have to use that many arguments... there are 2 other overloaded functions... one of them takes two parameters: the name of attribute and its value.

    But for the method as you requested it:

    http://msdn.microsoft.com/library/de...ringtopic3.asp


    "xmlns"
    prefix
    The namespace prefix of the attribute.

    "x"
    localName
    The local name of the attribute.

    null
    ns
    The namespace URI of the attribute.

    "urn:1"
    value
    The value of the attribute.

    Basically, the localname gets appended to any elements you write using StartElement(see note below)... so if the namespace is "x", when you write an element called "Beer" with a value of "2", the XMLWriter will automatically append "x" in front of "Beer", giving you:
    <x:Beer>2</x:Beer>

    Note: But, you could also do that using an overloaded function of StartElement... its really a horse a piece..
    Last edited by nemaroller; Jul 10th, 2004 at 10:09 AM.

  7. #7
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Originally posted by nemaroller
    Don't get drunk with the stuff man... the hangover might kill ya

    Take it slow...
    It isn't that bad, but I had one of those light bulb moments with it, and the mind started racing with what can be done.

  8. #8

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    ok after some coding i got this:
    <leechServerROOT>
    <FTP d2p1:Name="" xmlns:d2p1="[Insomnium's Palace]" />
    </leechServerROOT>
    I'd like to have:
    <FTP Name="[Insomnium's Palace]" />
    To write the attribute i'm using:
    Code:
    xtw.WriteStartAttribute("Name", "Insomniums Palace")
    Is it even possible at all?
    \m/\m/

  9. #9

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    Another question, if I have the following:

    <ROOT>
    <FTP>
    <NAME>lol</NAME>
    </FTP>
    <FTP>
    <SIZE>15</SIZE>
    </FTP>
    </ROOT>
    Will this raise any kind of error when reading it?
    Or will it read it up as if both "properties" Name and Size were right next to each other?
    \m/\m/

  10. #10
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    As a last resort, you can use the WriteRaw method.... since I haven't used the class since last year... I don't remember all its pecularities...

    As far as your second post... they will be interpreted as seperate entities... one without a name attribute, one without a size attribute.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width