Jump to content
Xtreme .Net Talk

Recommended Posts

Posted


<WebMethod()> Public Function GetUsers() As XmlDocument

Dim xmlDoc As New XmlDocument
Dim s As New System.Text.StringBuilder
Dim sPath As String
Dim sw As IO.StreamWriter
...
With s
.Append("<?xml version=" & """" & "1.0" & """" & "?>" & vbCrLf)
.Append("<Users>" & vbCrLf)
If Not dt Is Nothing Then
For i = 0 To dt.Rows.Count - 1
'here we create the entries for all files
.Append("<UserName>" & dt.Rows(i).Item(0) & "</UserName>" & vbCrLf)
Next
End If
.Append("</Users>" & vbCrLf)
End With
sPath = Server.MapPath("./documents") & "\fhdytxuu.xml"
sw = New System.IO.StreamWriter(sPath, False)
sw.Write(s)
sw.Flush()
sw.Close()
sw = Nothing
xmlDoc.Load(sPath)
IO.File.Delete(sPath)
Return xmlDoc
[/Code]

 

In a nutshell, I use a stringbuilder to build an xml document (which works), I load the XMLDocument (which works), and provide it from the webservice as an XMLDocument

 

Whatever program reads it, reads it as a node. This is not good, because the people who read it need to read an XML document

 

Am I using the wrong method here, or leaving a step out to allow my end user to read the document?

Read the Fovean Chronicles

Because you just can't spend your whole day programming!

Posted

You need a root node - All XML documents need root nodes...

 

ie:

<UserList>
 <Users>
   <UserName>
      User1
   </UserName>
 </Users>
</UserList>

 

Although, a better XML structure would be something like:

<UserList>
 <User>
   <UserName>
      User1
   </UserName>
   <FirstName>
      Bob
   </FirstName>
   <LastName>
      Smith
   </LastName>
 </User>
</UserList>

 

This way you can have multiple values for each user - makes things more flexible if you want to extend the amount of information you store in the file...

Bypass your proxy and get anonymous internet surfing FREE!
  • Administrators
Posted (edited)

Web methods return XML. Whatever data type you return is converted to SOAP and resturned.

If you are building the XML yourself that will just become another node in the result document.

 

What kind of information are you returning and if it has a particular structure could you not define a valid schema for it and let .Net do some of the work?

Edited by PlausiblyDamp

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

I recreated the node to resember yours, with the root of 'UserList' and the first child of 'Users', then for each username that it is returning, within Users, created a child 'UserName1', 'UserName2', etc

 

I then write it to an xmldocument using the streamwriter (perhaps I need serialization here?), then load the document just created to an XML document that I instantiate within the subroutine, then return that XMLdocument

 

The document is valid as a document within the webservice, in that you can read it and do all of the things that you would do to an XML document with it.

 

I have read on other sites that this is a case of .Net Webervices only returning nodes, not full documents, in which case I think I might just create the document as a file and return that.

Read the Fovean Chronicles

Because you just can't spend your whole day programming!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...