I am working on Xml in C#.net using visual studio 2005
For Example :: file1.xml Contains the following code
================================================== =========================================
<?xml version="1.0" encoding="utf-8" ?>
<JDF ID="6" Type="ProcessGroup" JobID="250055" Status="Waiting" Version="1.1" DescriptiveName="PackageInsertsK+C+M+Y1Sid">
<CustomerInfo CustomerID="GraphExp">
<Company OrganizationName="GraphExpo">
<Contact ContactTypes="Customer">
<Person FamilyName="JohnSwenson"/>
<Address City="Chicago" Street="2301 /Southlake /ShoreDrive" State="IL" PostalCode="60616"/>
<ComChannel Locator="" ChannelType="Phone"/>
<ComChannel Locator="" ChannelType="Fax"/>
<ComChannel Locator="" ChannelType="Email"/>
</Contact>
</Company>
</CustomerInfo>
<NodeInfo End="2003-04-30T11:11:57-05:00" Start="2003-04-30T11:11:57-05:00">ProductType="PrintedSheet" SourceSheet="1"</NodeInfo>
<AuditPool>
<Created Author="Joe Demo [AgentName=None [AgentVersion=None]" TimeStamp="2003-04-18T11:11:57-05:00"/>
</AuditPool>
<ResourceLinkPool>DescriptiveName="Wasteof1/2pages/1(information deleted for security and simplicty)</ResourceLinkPool>
</JDF>
================================================== =========================================
I am displaying the xml nodes/element in listbox ....
The listBox contains all the Nodes/element which is present in Xml file
================================================== =========================================
For Example :: ListBox contains nodes/element
JDF
CustomerInfo
Company
Contact
Person
Address
ComChannel
NodeInfo
AuditPool
Created
ResourceLinkPool
================================================== =========================================
But I have to display the attributes in dataGrid if i use the following Code
XmlNode x = root.SelectSingleNode("//JDF")
================================================== ==========
Based on selected item from listBox I have to display
the particular element attributes in the dataGrid
================================================== ======
If i am using nodeset in xml for searching the specified node
XmlNode x = root.SelectSingleNode("//LocalName'"+tree.SelectedNode.Fullpath+"'")
An unhandled exception has occured in your application .
localname'JDf\customerinfo\company\contact\comchan nel' has an invalid token.
If I am using Without Nodeset
XmlNode x = root.SelectSingleNode("//'"+tree.SelectedNode.Fullpath+"'")
An unhandled exception has occured in your application .
The Expression passed to this method should result in a NodeSet
================================================== ======
Based on selected item from listBox I have to display
the particular element attributes in the dataGrid
================================================== ========
Please Provide some solutions for this.....................................
================================================== ====================================
For ListBox Event .... I had written the Code
================================================== =========================================
private void listBox2_SelectedIndexChanged(object sender, System.EventArgs e)
XmlDocument doc = new XmlDocument();
doc.Load(("C:\\jdf.xml"));
XmlElement xRoot = doc.DocumentElement;
================================================== ================================= ====
XmlNodexNode=xRoot.SelectSingleNode("//'"+listBox2.SelectedItem.ToString()+"'");
The above mentioned code is not working
================================================== ===================================
Alternate line for above mentioned line
================================================== ==================================
XmlNode xNode = xRoot.SelectSingleNode("//JDF");
But this is working .. thing is each time i have to change the node like //NodeInfo manually
================================================== =================================
DataSet ds = new DataSet("myset");
DataTable dt = new DataTable("tab");
DataColumn c1 = new DataColumn();
DataColumn c2 = new DataColumn();
DataRow r;
c1.ColumnName = "Attribute_Name";
c1.ReadOnly = true;
c1.Unique = true;
dt.Columns.Add(c1);
c2.ColumnName = "Attribute_Value";
c2.ReadOnly = true;
c2.Unique = true;
dt.Columns.Add(c2);
ds.Tables.Add(dt);
foreach ( XmlAttribute attr in xNode.Attributes )
{
string text;
text = ""+attr.Name +" ==== "+ attr.Value +"";
r=dt.NewRow();
r["Attribute_Name"]=attr.Name;
r["Attribute_Value"]=attr.Value;
dt.Rows.Add(r);
ds.AcceptChanges();
}
dataGrid2.CaptionText="Attributes";
dataGrid2.SetDataBinding(ds,"tab");
}
================================================== ==================================
I had written the code for displaying the attributes in Datagrid its working
but I am not able to display the text value which is present between the tags
At the same time
I need the output like this.........................for that <JDF> element in datagrid
--------------------------------------------------------------------------------
JDF
Attribute_Name Attribute_value
==============================
ID || 6
Type || ProcessGroup
JobID || 250055
Status || Waiting
Version || 1.1
DescriptiveName|| PackageInsertsK+C+M+Y1Sid
----------------------------------------------------------------------------------
Based on selected item from listBox I have to display
the particular element attributes in the dataGrid
------------------------------------------------------------------------------------
please provide some solution for this............................../