Showing posts with label xml. Show all posts
Showing posts with label xml. Show all posts

Monday, March 26, 2012

Populate array from XML

Hi.
I have a two dimensional array. Is it possible to fill it with xml data?

Thanks,
ShawnOn Wed, 13 Jul 2005 16:43:49 +0200, "Shawn" <bossman100@.hotmail.com>
wrote:

>Hi.
>I have a two dimensional array. Is it possible to fill it with xml data?

I am guessing that the Xml contains two values that you want into the
array? What is the array and do you have a sample of the Xml.

You could also have a look on MSDN about readin XmlDocuments:

http://msdn.microsoft.com/library/d...lNodeReader.asp

Hope this helps

Tom

Populate datagrid from XML file using where type query

I am able to populate a datagrid from an XML variable using the
following:
Try
Dim ds As New DataSet
ds.ReadXml(New
StringReader(HttpContext.Current.Application("var").ToString))
dataMeet.DataSource = ds
dataMeet.DataBind()
Catch ex As Exception
error_email.fncErrorHandler(ex)
lblError.Text = ex.ToString
End Try
however this does not allow me to use a sql type query to select
exactly the data I want in the datagrid.
The query I am looking to achieve is actually very simple, just a
simple 'where' but I have no idea how to achieve this when binding to
an xml variable
The sql query and a sample xml file are pasted below:
select TITLE, FIRST_NAME || ' ' || LAST_NAME AS FULL_NAME, DEPT, EMAIL,
PHONE FROM DATABASE.TABLE "
WHERE MEMBERTYPE_CODE = 'MEM' ORDER BY MEMBER_ID
<NewDataSet>
<Table>
<MEMBERTYPE_CODE>OFF</MEMBERTYPE_CODE>
<LAST_NAME>Smith</LAST_NAME>
<FIRST_NAME>Harry</FIRST_NAME>
<TITLE>engineer</TITLE>
<DEPT>engineering</DEPT>
<EMAIL>harry.smith@dotnet.itags.org.email.address</EMAIL>
<PHONE>(111) 111-1111</PHONE>
</Table>
<Table>
<MEMBERTYPE_CODE>MEM</MEMBERTYPE_CODE>
<LAST_NAME>fred</LAST_NAME>
<FIRST_NAME>bloggs</FIRST_NAME>
<TITLE>Webmaster</TITLE>
<DEPT>Information Technology Services</DEPT>
<EMAIL>fred.blogs@dotnet.itags.org.email.address</EMAIL>
<PHONE>(111) 111-1112</PHONE>
</Table>
</NewDataSet>
Thank you for your timePerfect, just what I needed!
Thank you

Populate datagrid from XML file using where type query

I am able to populate a datagrid from an XML variable using the
following:

Try
Dim ds As New DataSet
ds.ReadXml(New
StringReader(HttpContext.Current.Application("var").ToString))
dataMeet.DataSource = ds
dataMeet.DataBind()
Catch ex As Exception
error_email.fncErrorHandler(ex)
lblError.Text = ex.ToString
End Try

however this does not allow me to use a sql type query to select
exactly the data I want in the datagrid.

The query I am looking to achieve is actually very simple, just a
simple 'where' but I have no idea how to achieve this when binding to
an xml variable

The sql query and a sample xml file are pasted below:

select TITLE, FIRST_NAME || ' ' || LAST_NAME AS FULL_NAME, DEPT, EMAIL,
PHONE FROM DATABASE.TABLE "
WHERE MEMBERTYPE_CODE = 'MEM' ORDER BY MEMBER_ID

<NewDataSet>
<Table>
<MEMBERTYPE_CODE>OFF</MEMBERTYPE_CODE>
<LAST_NAME>Smith</LAST_NAME>
<FIRST_NAME>Harry</FIRST_NAME>
<TITLE>engineer</TITLE>
<DEPT>engineering</DEPT>
<EMAIL>harry.smith@dotnet.itags.org.email.address</EMAIL>
<PHONE>(111) 111-1111</PHONE>
</Table>
<Table>
<MEMBERTYPE_CODE>MEM</MEMBERTYPE_CODE>
<LAST_NAME>fred</LAST_NAME>
<FIRST_NAME>bloggs</FIRST_NAME>
<TITLE>Webmaster</TITLE>
<DEPT>Information Technology Services</DEPT>
<EMAIL>fred.blogs@dotnet.itags.org.email.address</EMAIL>
<PHONE>(111) 111-1112</PHONE>
</Table>
</NewDataSet
Thank you for your timeHi gn,

You can use DataView's properties RowFilter and Sort to
perform functionality similar to 'WHERE' condition
and 'ORDER BY' in sql query. Following is sample code
snippet:

Dim dv As DataView = ds.Tables(0).DefaultView
dv.RowFilter = "MEMBERTYPE_CODE = 'MEM'"
dv.Sort = "LAST_NAME"
dataMeet.DataSource = dv
dataMeet.DataBind()

HTH

Elton Wang
elton_wang@.hotmail.com

>--Original Message--
>I am able to populate a datagrid from an XML variable
using the
>following:
> Try
> Dim ds As New DataSet
> ds.ReadXml(New
>StringReader(HttpContext.Current.Application
("var").ToString))
> dataMeet.DataSource = ds
> dataMeet.DataBind()
> Catch ex As Exception
> error_email.fncErrorHandler(ex)
> lblError.Text = ex.ToString
> End Try
>however this does not allow me to use a sql type query to
select
>exactly the data I want in the datagrid.
>The query I am looking to achieve is actually very
simple, just a
>simple 'where' but I have no idea how to achieve this
when binding to
>an xml variable
>The sql query and a sample xml file are pasted below:
>select TITLE, FIRST_NAME || ' ' || LAST_NAME AS
FULL_NAME, DEPT, EMAIL,
>PHONE FROM DATABASE.TABLE "
>WHERE MEMBERTYPE_CODE = 'MEM' ORDER BY MEMBER_ID
><NewDataSet>
> <Table>
> <MEMBERTYPE_CODE>OFF</MEMBERTYPE_CODE>
> <LAST_NAME>Smith</LAST_NAME>
> <FIRST_NAME>Harry</FIRST_NAME>
> <TITLE>engineer</TITLE>
> <DEPT>engineering</DEPT>
> <EMAIL>harry.smith@.email.address</EMAIL>
> <PHONE>(111) 111-1111</PHONE>
> </Table>
> <Table>
> <MEMBERTYPE_CODE>MEM</MEMBERTYPE_CODE>
> <LAST_NAME>fred</LAST_NAME>
> <FIRST_NAME>bloggs</FIRST_NAME>
> <TITLE>Webmaster</TITLE>
> <DEPT>Information Technology Services</DEPT>
> <EMAIL>fred.blogs@.email.address</EMAIL>
> <PHONE>(111) 111-1112</PHONE>
> </Table>
></NewDataSet>
>Thank you for your time
>.
Perfect, just what I needed!

Thank you

Saturday, March 24, 2012

Populate dropdown list with XML

How can I fill a dropdown list with XML data. Simplest way please. I would like to user server.mappath to get the data from the file. Is it possible to use a recordset

I need to populate the ID and the value of the record.

Code sample appreciated...thanksPlease see below code, that helps for your question.

Here is the simple XML file, I am using to bind to dropdownlist and name is as Xmlfile.xml


<?xml version="1.0" encoding="utf-8" ?>
<DataList>
<Student>
<Name>Creator</Name >
<Roll>101</Roll >
</Student >
<Student>
<Name>Maintainer</Name >
<Roll>102</Roll >
</Student
</DataList>

and I am using this file to bind with Dropdownlost in page load event. Assuming DropDownList server control name is DropDownList1


Dim Ds As New System.Data.DataSet
Ds.ReadXml("D:\WebSites\VS2005First\XMLFile.xml")

DropDownList1.DataSource = Ds.Tables(0).DefaultView
DropDownList1.DataTextField = "Roll"
DropDownList1.DataValueField = "Name"
DropDownList1.DataBind()

Hope this helps you!
ok that is pretty easy,fist of all u need to populate ur xml data to your datagrid then bind it to ur dropdownlist.

xml file
<root>
<userName>Bob</userName>
<userID>1</userID>
</root
vb.net
'read your data from your datagrid
'assuming ur xml is your root directory
'

Dim ds As DataSet
ds.ReadXml(Server.MapPath("file.xml"))
'bind your dataset to your dropdown list
DropDownList1.DataSource = ds
'assign the element of ur xml to the ddl
DropDownList1.DataTextField = "userName"
DropDownList1.DataValueField = "userID"
DropDownList1.DataBind()

hope that help.Happy coding
Thank you all for replying - I will try the suggestions given

Wednesday, March 21, 2012

Populate treeview from dataset

In a webform how do I populate a treeview from a dataset?
All the examples seem to use xml.
Thanks in AdvanceJust loop through the dataset and add items to the treeview programmatically.

There is no simple way like Treeview1.Data= YourDataSet, so you just have to do something like:

'I dont know the specific code for adding to a treeview, but it would be somthing like this
Dim tItem as TreeViewItem
For x = 0 to ds1.Rows.Count-1

tItem = New TreeViewItem
tItem.text = ds1.Rows(x).Item(0).ToSTring()
TreeView1.Items.Add(tItem)
Next

populating a drop-down problem

Hello - I have a dropdown of US States that I populate from an xml file.

I then have a user log in to my site and their details are pulled off a database - including their address with state code.

I then set the selected value of the drop down to the users state.

The problem I have is if the sate on the database is empty or incorrect for some reason. When I set the selected value of the drop down list, I get an error because I'm trying to set it to a value that isn't there.

How do I get around this?

I need some sort of way to say - select this value from the dropdown only if the value exists - without giveing the error.

Any ideas?

ThanksmyComboBox.Items.Count will give you the number of items in the combo. If the number is not 0, you can use the SelectedValue, otherwise not.
That's not quite the problem but thanks anyway - what I mean is:

Lets say I have a drop down list with the values of

NY
CY
FL
NJ

and then I use dropdownList1.selectedValue = "DFGDF"

It's not going to find that value right?

What I wanted to know was is it possible to find out before I specify the selected value whether the value is actually in the list or not.

I have found a way round it though using:

Try
dropDownStates.SelectedValue = usrRow.Item("State")
Catch ex As Exception

End Try

At least that way I don't get an error but I was wondering if there's a way of telling what values are in the dropdown before specifying which is selected..

Thanks anyway.
Why not populate the ddl from the database and then you are sure that there is an entry for every possible selected item?

HTH
Well - the list of states is correct in that all the codes are correct and all the states are there. I need to provide all the states in the drop down to allow new users to sign up and for existing users to pick a new state if they move house.

The problem I have is that the data I'm initialy supllied with probably wont be perfect. I have no control over this data either - I just get the data and have to eork with it as it is. So I have to account for some of the users on the datanase not having the correct state code. Some might not have a code at all and others may be 'New York' rather then NY..

I suppose a way round it would be to:

create a dataset from the xml file of states

cerate a dataView from the dataset and see if the users state (NY for eaxmple) was in there.

if it was, I could then set the selected value of the dropdown to that value otherwise I would just leave it.

That just sounds like a long way of doing it though.

Isn't there some property of the dropdown like

dropdownlist.containsvalue ?

That would make it much easier.

Friday, March 16, 2012

Populating a Stream object with XML and then convert Stream into a String Options

I am trying to populate a Stream via an XML Serializer and then
convert that stream of xml into a string.

I have been able to successfully serialize an object into a physical
xml file written to my local disk. The XML file has content and looks
as I would expect, here is the code for that action:

TextWriter writer = new StreamWriter(@dotnet.itags.org."c:\test.xml");
serializer.Serialize(writer, oData);

When I try to to serialize my object to a stream of xml and then
convert to a string I get no content in the string. Both the
MemoryStream and StreamWriter object appear to have the correct byte
size after I populate them with the serialized data. Is there an
alternative way I should be doing this? Here is the code I'm using:

MemoryStream ms = new MemoryStream();
StreamWriter sw = new StreamWriter(ms);

serializer.Serialize(sw, oData);

StreamReader sr = new StreamReader(ms);

string test = "";
test = sr.ReadToEnd(); //No content is populated, why?

Thank you,
Darren

dstahl:

MemoryStream ms = new MemoryStream();
StreamWriter sw = new StreamWriter(ms);

serializer.Serialize(sw, oData);

StreamReader sr = new StreamReader(ms);

string test = "";
test = sr.ReadToEnd(); //No content is populated, why?

Thank you,
Darren

Hi Darren,

In your code, after you serialize your sw, you couldn't new it again, because that will create sw again.

Try to cancel that line : "StreamReader sr = new StreamReader(ms); ". As you know, if you do like your way, ms has nothing, then sw has nothing too, even if you have initialize the sw before.

Hope this helps. Thanks.