Results 1 to 5 of 5
  1. #1
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Adding a namespace to a XML File Visual Basic net (.Net 2005)

    Hi,
    A colleague of mine is having some problems with his name space and asked if i'd mind posting a question for him....
    He is using the following code to write an XML file:

    AdoCn = New SqlConnection(DSN)
    AdoCn.Open()
    SQLAdap = New SqlDataAdapter(SQL, AdoCn)
    SQLAdap.Fill(DataS, WebServiceID)
    SQLAdap.Dispose()
    DataS.WriteXml(XMLPath)

    This outputs the following XML file:
    <?xml version="1.0" standalone="yes" ?>
    - <datareader>
    - <_x0031_088>
    <UserName>uname</UserName>
    <Password>pwd</Password>
    <Event_ID>43687</Event_ID>
    <Spirit_ID>17219</Spirit_ID>
    <EstablishmentFullName>Gravesend Grammar School</EstablishmentFullName>
    <Postcode>DA12 2PR</Postcode>
    <Type_ID>10</Type_ID>
    <Sub_Type>A: Active</Sub_Type>
    <UserName1>Jason Gould</UserName1>
    <StartDate>30/Aug/2004 00:00:00</StartDate>
    <Due_Date>01/Sep/2004 00:00:00</Due_Date>
    <Priority>1</Priority>
    <Status>A</Status>
    <Event_Name>TEST</Event_Name>
    <ActionUser>Jason Gould</ActionUser>
    <ActionDate>01/Sep/2004 00:00:00</ActionDate>
    <MarketingAuditId>27494</MarketingAuditId>
    </_x0031_088>
    - <_x0031_088>
    <UserName>uname</UserName>
    <Password>pwd</Password>
    <Event_ID>43687</Event_ID>
    <Spirit_ID>17219</Spirit_ID>
    <EstablishmentFullName>Gravesend Grammar School</EstablishmentFullName>
    <Postcode>DA12 2PR</Postcode>
    <Type_ID>10</Type_ID>
    <Sub_Type>A: Active</Sub_Type>
    <UserName1>Jason Gould</UserName1>
    <StartDate>30/Aug/2004 00:00:00</StartDate>
    <Due_Date>01/Sep/2004 00:00:00</Due_Date>
    <Priority>1</Priority>
    <Status>A</Status>
    <Event_Name>TEST</Event_Name>
    <ActionUser>Barbara Spork</ActionUser>
    <Narrative>wrfewgwr</Narrative>
    <ActionDate>30/Aug/2004 11:31:26</ActionDate>
    <MarketingAuditId>27495</MarketingAuditId>
    </_x0031_088>
    </datareader>

    However I want the output to look like this

    <?xml version="1.0" standalone="yes" ?>
    - <datareader xmlns="http://domain.co">
    - <_x0031_088>
    <UserName>uname</UserName>
    <Password>pwd</Password>
    <Event_ID>43687</Event_ID>
    <Spirit_ID>17219</Spirit_ID>
    <EstablishmentFullName>Gravesend Grammar School</EstablishmentFullName>
    <Postcode>DA12 2PR</Postcode>
    <Type_ID>10</Type_ID>
    <Sub_Type>A: Active</Sub_Type>
    <UserName1>Jason Gould</UserName1>
    <StartDate>30/Aug/2004 00:00:00</StartDate>
    <Due_Date>01/Sep/2004 00:00:00</Due_Date>
    <Priority>1</Priority>
    <Status>A</Status>
    <Event_Name>TEST</Event_Name>
    <ActionUser>Jason Gould</ActionUser>
    <ActionDate>01/Sep/2004 00:00:00</ActionDate>
    <MarketingAuditId>27494</MarketingAuditId>
    </_x0031_088>
    - <_x0031_088>
    <UserName>uname</UserName>
    <Password>pwd</Password>
    <Event_ID>43687</Event_ID>
    <Spirit_ID>17219</Spirit_ID>
    <EstablishmentFullName>Gravesend Grammar School</EstablishmentFullName>
    <Postcode>DA12 2PR</Postcode>
    <Type_ID>10</Type_ID>
    <Sub_Type>A: Active</Sub_Type>
    <UserName1>Jason Gould</UserName1>
    <StartDate>30/Aug/2004 00:00:00</StartDate>
    <Due_Date>01/Sep/2004 00:00:00</Due_Date>
    <Priority>1</Priority>
    <Status>A</Status>
    <Event_Name>TEST</Event_Name>
    <ActionUser>Barbara Spork</ActionUser>
    <Narrative>wrfewgwr</Narrative>
    <ActionDate>30/Aug/2004 11:31:26</ActionDate>
    <MarketingAuditId>27495</MarketingAuditId>
    </_x0031_088>
    </datareader>

    Note: I have added the namespace xmlns="http://domain.co" at the top by the datareader opening tag.

    I have had a search around but can't find anything obvious.

    Regards,

  2. #2
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Adding a namespace to a XML File Visual Basic net (.Net 2005)

    Would you mind elaborating on the differences between the two outputs? I glanced over them and didn't see any obvious differences (without spending more time to do a bit-by-bit comparison)...

  3. #3
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Adding a namespace to a XML File Visual Basic net (.Net 2005)

    The namespace xmlns="http://domain.co" has been added after datareader at the top.

  4. #4
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Adding a namespace to a XML File Visual Basic net (.Net 2005)

    Ahh - I see now. Thanks for the clarification.

    There is a Namespace property of the DataSet object that you can set prior to writing the XML. I haven't tired this, but doing so *should* carry over to the exported XML.

  5. #5
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Adding a namespace to a XML File Visual Basic net (.Net 2005)

    Thanks Mark,

    I told my colleague and he found the setting you mentioned and was a very happy man! He hasn't tried it yet as he's been bogged down with some other work but if it works i'll post and let you know.

    Thanks again.

Posting Permissions

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