Re: Reading XML Documents
- From: David Lozzi <dlozzi(remove-this)@delphi-ts.com>
- Date: Mon, 19 Nov 2007 13:07:01 -0800
That's doing basically the same thing. I could loop through the .Read but the
script gets messy at best. The method i have now i can at least know where in
the script each group of nodes are being processed.
I've seen methods like ReadStartElement("users") which I tried but it threw
an error
..MoveToContent()
TimeEntry("Title=" & .GetAttribute("Title") & " Description=" &
..GetAttribute("Description"))
..ReadStartElement("users") **LINE 215
..Read() 'user
System.Xml.XmlException: Element 'users' was not found. Line 1, position 192.
at System.Xml.XmlReader.ReadStartElement(String name)
at SharePointExportImport.Form1.btnImport_Click(Object sender, EventArgs
e) in C:\Documents and Settings\Administrator\My Documents\Visual Studio
2005\Projects\SharePointExportImport\SharePointExportImport\Form1.vb:line 215
Thanks!
--
David Lozzi
Delphi Technology Solutions
Blog: www.lozzi.net
"Alexey Smirnov" wrote:
On Nov 19, 9:41 pm, David Lozzi <dlozzi(remove-this)@delphi-ts.com>.
wrote:
Howdy,
I have an XML document, see below. I'm trying to read from it and pull
attributes and elements as needed. The only thing i've been able to get to
work is using the Read method of the XmlReader class. I see there are other
methods of moving around but none appear to be working properly. Could you
suggest a better approach following the below flow?
<primarysite Title="Reading Deparment" Description="" Theme=""
ServerRelativeUrl="/">
<users>
<user Name="ROCK\administrator" LoginName="ROCK\administrator" Email="">
<roles />
</user>
<user Name="System Account" LoginName="SHAREPOINT\system" Email="">
<roles />
</user>
</users>
Dim xConfig As New XmlTextReader("c:\wss\Reading_Deparment.xml") '"
& PrimarySiteFile & ".xml")
With xConfig
.MoveToContent()
TimeEntry("Title=" & .GetAttribute("Title") & " Description=" &
.GetAttribute("Description"))
.Read() 'users
.Read() 'user
Do While .Name = "user"
TimeEntry("LoginName=" & .GetAttribute("LoginName") & "
Email=" & .GetAttribute("Email") & " Name=" & .GetAttribute("Name"))
.Read() ' roles
.Read() ' user or role
If .Name = "role" Then
'process the role
End If
.Read() ' user
Loop
.ReadEndElement() ' users
Thanks!
--
David Lozzi
Delphi Technology Solutions
Blog:www.lozzi.net
Hi David,
I think the easiest way is to use XmlDocument and XmlNodeList.
For example:
Dim xml as XmlDocument = New XmlDocument()
xml.Load(HttpContext.Current.Server.MapPath("...xml"))
Dim nodes as XmlNodeList = xml.SelectNodes("//users/user")
For each n as XmlNode In nodes
Response.Write(n.Attributes["Name"].Value)
Next
Hope this helps
- Follow-Ups:
- Re: Reading XML Documents
- From: Alexey Smirnov
- Re: Reading XML Documents
- References:
- Re: Reading XML Documents
- From: Alexey Smirnov
- Re: Reading XML Documents
- Prev by Date: Re: Reading XML Documents
- Next by Date: Re: OT- Mail list services
- Previous by thread: Re: Reading XML Documents
- Next by thread: Re: Reading XML Documents
- Index(es):
Relevant Pages
|