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 / ASP.NET / General / May 2008

Tip: Looking for answers? Try searching our database.

xml format problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
CindyH - 20 May 2008 07:12 GMT
Hi

I'm using the following code to create xml string:

Dim Doc As New System.Xml.XmlDocument
Dim newAtt As System.Xml.XmlAttribute

Dim dec As System.Xml.XmlDeclaration
dec = Doc.CreateXmlDeclaration("1.0", Nothing, Nothing)
dec.Encoding = "UTF-8"
Doc.AppendChild(dec)

Dim DocRoot As System.Xml.XmlElement = Doc.CreateElement("userlist")
newAtt = Doc.CreateAttribute("ACTION")
newAtt.Value = vAction
DocRoot.Attributes.Append(newAtt)

newAtt = Doc.CreateAttribute("VENDORNAME")
newAtt.Value = vVendorName
DocRoot.Attributes.Append(newAtt)
Doc.AppendChild(DocRoot)

Dim amouser As System.Xml.XmlNode = Doc.CreateElement("amouser")
newAtt = Doc.CreateAttribute("AMOAID")
newAtt.Value = vAMOAID
amouser.Attributes.Append(newAtt)

newAtt = Doc.CreateAttribute("VENDORUSERNAME")
newAtt.Value = vH2UserName
amouser.Attributes.Append(newAtt)

newAtt = Doc.CreateAttribute("AMOATOKEN")
newAtt.Value = vAMOAToken
amouser.Attributes.Append(newAtt)

DocRoot.AppendChild(amouser)

Dim xmlstring = Doc.OuterXml

The result looks like this:

<?xml version="1.0" encoding="UTF-8"?>
 <userlist ACTION="redirectuser" VENDORNAME="H2Digital">
    <amouser AMOAID="bb224c2a-fe8a-4c3f-acf4-6c0986b8cf78"
VENDORUSERNAME="xrivera@hotmail.com"
    AMOATOKEN="hx0gH6e8PvswEzaA8oXPoVIY/KvnbP2/" />
</userlist>

I need the result to look like this: with </amouser> instead of />

<?xml version="1.0" encoding="UTF-8"?>
 <userlist ACTION="redirectuser" VENDORNAME="H2Digital">
    <amouser AMOAID="bb224c2a-fe8a-4c3f-acf4-6c0986b8cf78"
VENDORUSERNAME="xrivera@hotmail.com"
     AMOATOKEN="hx0gH6e8PvswEzaA8oXPoVIY/KvnbP2/" </amouser>
</userlist>

Does anyone know what I'm doing wrong here?
Thanks,
Cindy
Anthony Jones - 20 May 2008 08:22 GMT
> Hi
>
[quoted text clipped - 54 lines]
>
> Does anyone know what I'm doing wrong here?

Your not doing anything wrong the output is correct.  I can't think why you
need to specifically have a closing tag rather than the short form /> but if
you do:-

  amouser.InnerText  = ""

BTW use import of System.Xml to eliminate the long type names.

Also why not simply use the elements .SetAttribute method to create the
attributes instead of creating them as nodes, code would look a lot simpler

Signature

Anthony Jones - MVP ASP/ASP.NET

CindyH - 20 May 2008 13:17 GMT
Can you give me an example of how to use the .SetAttribute
in my code?

>> Hi
>>
[quoted text clipped - 68 lines]
> attributes instead of creating them as nodes, code would look a lot
> simpler
Anthony Jones - 20 May 2008 21:20 GMT
> Can you give me an example of how to use the .SetAttribute
> in my code?

Hows this :-

Imports System.Xml

...

Dim Doc As New XmlDocument

Dim dec As System.Xml.XmlDeclaration
dec = Doc.CreateXmlDeclaration("1.0", Nothing, Nothing)
dec.Encoding = "UTF-8"
Doc.AppendChild(dec)

Dim DocRoot As XmlElement = Doc.CreateElement("userlist")
Doc.AppendChild(DocRoot)

DocRoot.SetAttribute("ACTION", vAction)
DocRoot.SetAttribute("VENDORNAME", vVendorName)

Dim amouser As XmlElement  = Doc.CreateElement("amouser")
DocRoot.AppendChild(amouser)

amouser .SetAttribute("AMOAID", vAMOAID)
amouser .SetAttribute("VENDORUSERNAME", vH2UserName)
amouser .SetAttribute("AMOATOKEN", vAMOAToken)

Dim xmlstring = Doc.OuterXml

Signature

Anthony Jones - MVP ASP/ASP.NET

CindyH - 20 May 2008 13:29 GMT
amouser.InnerText  = ""
This worked by the way - thanks!

>> Hi
>>
[quoted text clipped - 68 lines]
> attributes instead of creating them as nodes, code would look a lot
> simpler

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.