473,394 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

how to get root element attribute of xml file with c#?

Hi,
I have a xml file as follow:
----------------------------------------
<?xml version="1.0" encoding="gb2312"?>
<Mydata date="2006-05-16">
<personalData>
<title>good book</title>
<author>james</author>
<price>58.3</price>
</personalData>
<personalData>
<title>nice book</title>
<author>peter</author>
<price>30.0</price>
</personalData>
</Mydata>
--------------------------------------
my problem is: how to get root element Mydata's attribute date with c#?

thanks.

May 18 '06 #1
2 15832
// Heres a possible solution
// Seeing the XML is small its fair to load it into an XmlDocument
object.
// Then use some Xpath to get your value

using System.Xml;

XmlDocument xdoc = new XmlDocument();
xdoc.Load(<< URL for the file containing the XML Document to load >>);
string yourDate = xdoc.SelectSingleNode("/Mydata/@date").Value ;

Dickster

May 18 '06 #2
I'll tyr it, Thanks.

"dickster" <gd***@kerrhenderson.com>
??????:11**********************@j55g2000cwa.google groups.com...
// Heres a possible solution
// Seeing the XML is small its fair to load it into an XmlDocument
object.
// Then use some Xpath to get your value

using System.Xml;

XmlDocument xdoc = new XmlDocument();
xdoc.Load(<< URL for the file containing the XML Document to load >>);
string yourDate = xdoc.SelectSingleNode("/Mydata/@date").Value ;

Dickster

May 18 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Russell O'Connor | last post by:
The following XML and Schema doesn't validate in Visual Studio .NET 2003. Is there some mistake I'm making, or is VS.NET in error. The error is r:\test2.xml(3): The key sequence 'foo' in Keyref...
4
by: Mythran | last post by:
I have a file I'm using as a Configuration file (configuration as in options and such). When I create the xml file in the .Net IDE, it places the following (snip): <Configuration xmlns="Blah">...
1
by: SideByEach | last post by:
Is there any way to determine what would be the XML's root node in a XmlSchema class? I'm not sure if this is even possible since "XmlSchemaElement" objects don't have a parent element. I realize...
6
by: TS | last post by:
Hi, i have a problem validating xml against schema. I used http://apps.gotdotnet.com/xmltools/xsdvalidator/Default.aspx validator and it says it is fine. Can you tell me why this doesn't work? ...
16
by: TT (Tom Tempelaere) | last post by:
Hi all, I created an XSD to define the structure of an XML file for my project. I made an XML file linked to the XSD using XmlSpy. The problem is that if I read the file using .NET XmlDocument...
1
by: Tomas | last post by:
When I try to load my xslt i get an xml exception with the message "Root element is missing". The stylesheet works when I preview it in stylus studio, but apparently not in my application. Any...
0
by: Dave Hill | last post by:
Forgive a newbie question. I'm learning the .NET XML environment. In the walkthrough on using XML designer to create an xsd, there is no discussion of the root element of the target xml document....
9
by: Mark Olbert | last post by:
I'm trying to serialize (using XmlSerializer.Serialize) a class that I generated from an XSD schema using XSD.EXE /c. The problem I'm running into is that the root element needs to be unqualified,...
4
by: johnsonkt | last post by:
hi all , when m trying to validate my xml using xsd file it gives me the following error "Data at the root level is invalid. Line 1, position 1" i tried to open the XML file using IE and there...
0
by: icesign | last post by:
I know that the selector of these elements has a scope relative to the element being declared, but maybe there is a way to get beyond bounds of this scope or maybe just a way to extend base element?...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.