XML 2 Datagrid Question

R

Raghuvansh

I am databinding a grid to an XML source (given below).

I am displaying the grid contents inside an
TemplateColumn/ItemTemplate using regular <%#
DataBinder.Eval(Container.DataItem, "Net-Change-Price") %> tags.

My question is:
How can I access/display the attributes of an XML node. More
specifically in the current example, how can I access/display 'symbol'
attribute in the 'equity-quote' node?

Thanks in advance.


Databinding code:
-------
MyStocksDataSet.ReadXml(http://quotes.nasdaq.com/quote.dll?mode=stock&page=xml&symbol=BAESF)
MyStocksDataGrid.DataSource = MyStocksDataSet
MyStocksDataGrid.DataBind()

XML
------
<?xml version="1.0" ?>
<nasdaqamex-dot-com>
<equity-quote symbol="BAESF" ilx-symbol="BAESF"
hyperfeed-symbol="BAESF" telesphere-symbol="BAESF" cusip="G1489618">
<issue-name>BAES SYSTEMS PLC</issue-name>
<market-status>O</market-status>
<market-center-code>Other OTC</market-center-code>
<issue-type-code>Foreign Issue</issue-type-code>
<todays-high-price>0</todays-high-price>
<todays-low-price>0</todays-low-price>
<fifty-two-wk-high-price>3.2</fifty-two-wk-high-price>
<fifty-two-wk-low-price>1.75</fifty-two-wk-low-price>
<last-sale-price>2.925</last-sale-price>
<net-change-price>unch</net-change-price>
<net-change-pct>unch</net-change-pct>
<share-volume-qty>0</share-volume-qty>
<previous-close-price>2.925</previous-close-price>
<current-pe-ratio>N/A</current-pe-ratio>
<total-outstanding-shares-qty>0</total-outstanding-shares-qty>
<current-yield-pct>0.000000</current-yield-pct>
<earnings-actual-eps-amt>0</earnings-actual-eps-amt>
<cash-dividend-amt>0</cash-dividend-amt>
<cash-dividend-ex-date>19691231</cash-dividend-ex-date>
<sp500-beta-num>0.200000</sp500-beta-num>
<trade-datetime>20031217 10:17:24</trade-datetime>
<trading-status>ACTIVE</trading-status>
<market-capitalization-amt>0</market-capitalization-amt>
<option-root-symbol symbol="" />
</equity-quote>
</nasdaqamex-dot-com>
 
V

vMike

One way might be as follows.
The DataBinder.Eval accepts a third argument which is a format command. for
example "{0,c}" is for currency format (the 0 is always 0) and the c is for
currency. One problem though is that the format must be of the date type of
the data defined by the XML schema or by the data type of the column if you
have added columns to you data. If you don't have a schema file all xml
values are considered strings and the format argument will not help for
numbers. If you want to create the schema, in my experience (which is not a
lot) the best way to get a running start on the schema file is to load the
xml file to a data set and infer schema (ds.ReadXml(yourXMLPathandFile,
XmlReadMode.InferSchema) and then save it with schema
(ds.writeXML(strXMLPathandFile, XmlWriteMode.WriteSchema) Then you can
change the data types etc.
Hope this helps.
 
M

McP

Anyone else having a problem with that nasdaq url? It used to work
until around Dec. 18. Now the resulting xml has no data in it, but
the other page types (like multi) work fine.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,273
Latest member
DamonShoem

Latest Threads

Top