How I can binding specified xml node to datagridview?

hello
please, i am new in c#;
I have xml file, i displayed the first node within form in c#, this node have attribute is called 'id', now i want to display all nodes that have attribute is called 'father' its value equal to id value of the displayed node.
xml file:
<?xml version="1.0" encoding="UTF-8"?>
<tree>
<grand name="aaa" id="1" sex="m" status="d" child="2" father=""></grand>
<grand name="ddd" id="12" sex="m" status="d" child="" father="1"></grand>
<grand name="bbb" id="11" sex="m" status="d" child="1" father="1"></grand>
<grand name="ccc" id="111" sex="m" status="d" child="1" father="11"></grand>
<grand name="ddd" id="1111" sex="m" status="d" child="3" father="111"></grand>
<grand name="eee" id="11111" sex="f" status="d" child="" father="1111"></grand>
<grand name="fff" id="11112" sex="m" status="d"child="" father="1111"></grand>
</tree>
c# code that display the first node is:
InitializeComponent();
XDocument xdoc = XDocument.Load(" http://domaim.net/tree/index.xml");
var name = xdoc.Descendants("grand").First().Attribute("name").Value;
var sex = xdoc.Descendants("grand").First().Attribute("sex").Value;
var alive = xdoc.Descendants("grand").First().Attribute("status").Value;
var child = xdoc.Descendants("grand").First().Attribute("child").Value;
var id = xdoc.Descendants("grand").First().Attribute("id").Value;
var father = xdoc.Descendants("grand").First().Attribute("father").Value;
textBox1.Text = name;
if (sex == "m") textBox2.Text = "male"; else textBox2.Text = "female";
if (child == "") textBox4.Text = "no child"; else textBox4.Text = child;
if (alive == "d") textBox3.Text = "dead"; else textBox3.Text = "alive";
here I displayed  the node its id="1", now i want to display all nodes that its "father" attribute is equal 1. i want to display thier attributes of these nodes within datagridview,(bbb & ddd).
thank you for all.

Try this.  You have an error in the XML that you need to put a space before child in the last row.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
public partial class Form1 : Form
public Form1()
InitializeComponent();
DataSet ds = new DataSet();
ds.ReadXml(@"c:\temp\index.xml");
dataGridView1.DataSource = ds.Tables["grand"];
DataTable fatherRows = ds.Tables["grand"].AsEnumerable()
.Where(x => x.Field<string>("father") == "1").CopyToDataTable();
dataGridView2.DataSource = fatherRows;

Similar Messages

  • How to binding incoming xml node list to the tree control as dataProvider

    Recently, I faced into one issue: I want to binding incoming xml node (it's not avaliable at start) list to the tree control as a dataProvider.
    Since the incoming xml node list is not avaliable at beginning but I needs to bind it to the tree, so I create one virtual one in the xml, and prepare to remove it before the tree is shown. (ready for the actual node adding). But It did not work.
    Please see the presudo-code here:
    1.  Model layer(CsModel.as)
    public class CsModel
            [Bindable]
            public var treeXML:XML=<nodes><car label="virtualOne" id="1">
                                   </car></nodes>;
            (Here, I want to build binding relationship on the <car/> node,
             one 'virtual/stub' node is set here with lable="virtualOne".
             But this node will be deleted after IdTree
             control is created completely.)      
            [Bindable]
            public var treeData:XMLList =new XMLListCollection(treeXML.car);
    2. view layer(treePage.mxml)
            private var _model:CsModel = new CsModel();
            private function addNode():void
                    var newNode:XML=<car/>;
                    newNode.@label="newOne";
                    newNode.@id=1;
                    _model.treeXML.appendChild(newNode);
                             private function cleanData():void
                                     delete _model.treeXML.car;
            <mx:VBox height="100%" width="100%">
            <mx:Button label="AddNode" click="addNode()" />
            <mx:Tree id="IdTree"  labelField="@label"
              creationComplete="cleanData()"
              dataProvider="{_model}"/>
        </mx:VBox>
    3. Top view layer (App.Mxml)
    <mx:application>
        <treePage />
    </mx:application>
    For method: cleanData(),It's expected that when the treePage is shown, we first delete the virutalOne to provide one 'clear' tree since we don't want show virtualOne to the user. The virutalOne node just for building the relationship between treeData and treeXML at beginning. But the side effect of this method, I found, is that the relationship between treeXML and treeData was cut off. And this leads to that when I added new node (by click the 'addNode' button) to the xmlXML, the xmlData was not affected at all !
    So Is there any other way to solve this issue or bind the incoming xml node list to the xmlListCollection which will be used as Tree control's dataProvider ?

    If u want to display the name : value then u can do like this
    <xsl:eval>this.selectSingleNode("name").nodeName</xsl:eval> : <xsl:value-of select="name" />

  • How I can create a XML file from java Aplication

    How I can create a XML file from java Aplication
    whith have a the following structure
    <users>
    <user>
    <login>anyName</login>     
    <password>xxxx</password>
    </user>
    </users>
    the password label must be encripted
    accept any suggestion

    Let us assume you have all the data from the jsp form in an java bean object..
    Now you want a xml file. This can be acheived in 2 ways
    1. Write it into a file using java.io classes. Say you have a class with name
    write("<name>"+obj.getName+</name>);
    bingo you have a flat file with the xml
    2. Use data binding to do the trick
    will recommend JiBx and Castor for the 2nd option
    Regards,
    Rajagopal

  • How we can show the xml data without any attribute in a flex tree (without having any label field) ?

    how we can show the following data in a flex tree (without having any
    label field) ?
    <?xml version="1.0"?>
    <rootNode>
            <childNode>
            < subchildNode >
                    <valueNode>1000</valueNode >
                    < valueNode >999-888-777</valueNode >
                    < valueNode >STORTZ</valueNode >
                    < valueNode >PAM STORTZ</valueNode >
                    < valueNode >88 ST. MORTON ROAD</valueNode>
            </subchildNode>
            </childNode >
    </rootNode >

    as is - no how
    wrap those xml chunk with a class having clear public properties like:
    public class dataRecord {
         protected var xml:XML;
         function dataRecord(xml:XML) {
              this.xml = xml;
         public function get id ():String {
              return XML(xml.descendants("valueNode")[0]).toString();
         // and so on
    simpliest way is to change xml structure to use attributes than wrapping that thing with AS code, it's time consuming and non efficient.

  • How to find in a xml node by its localName ?

    i have an a xml with namespace
    but i dont know this namespace and how many its in this xml
    so i know tah will be a tag named hash
    i want to get the actual value
    and assign a new value
    thanks

    Hi,
    With debug mode using breakpoints you should be able to stop the app at the time you data is coming back and see the structure of data result.
    Johnny
    Please rate answers

  • How to select a specific XML node with XPath

    Hi,
    I'm trying to a select a specific node from my XML data using the XPath Builder.  For example, say I have a process variable 'xmlData' with the
    following contents:
        User 1
        101
        User 2
        102
    I can successfully use the following expression to retrieve the name of
    a specific user:
    (/process_data/xmlData/users/user[userid='102'])/name
    The problem is I need to use another process variable for the selection
    key.  For Example:
    (/process_data/xmlData/users/user[userid=/process_data/@userId])/name
    But this always returns null.  I've tried surrounding /process_data/@userId
    with single quotes, double quotes, and event {$..$}. 
    Any help would be greatly appreciated.
    Thanks.

    Hi,
    Thanks for the quick replies.  I gave a bit of a bad example, as the
    userid in my data is really a string, not a number.
    A better example is:
        User 1
        user1
        User 2
        user2
    I can get the following to work perfectly:
    (/process_data/xmlData/users/user[userid='user2'])/name
    but I can't get it to work with
    /process_data/@userId = "user2"
    (/process_data/xmlData/users/user[userid=/process_data/@userId])/name
    Thanks.

  • How to determine in an XML node exists in Coldfusion

    If I have XML that looks something like this:
    <manifest>
        <state ID="20" name="State 2">
            <person>john.black</person>
        </state>
        <state ID="30" name="State 2">
            <person>bill.doe</person>
            <group>Group2</group>
        </state>
    </manifest>
    Where <group> may or may not exist under <state>, how do I determine if <group> exists when I'm parsing this XML? 
    This is the code I'm working with currently:
    <cfset szXMLFile = "Manifest.xml">
    <cfset XMLDoc = xmlParse(szXMLFile)>
    <cfset StateNodes = xmlSearch(XMLDoc,'/manifest/state')>
    <cfoutput>
    <cfloop from="1" to="#ArrayLen(StateNodes)#" index="i">
        <cfset StateXML = xmlparse(StateNodes[i])>
        <cfloop index="p" from="1" to="#ArrayLen(StateXML.state.person)#">
            <cfoutput>Person: #StateXML.state.person[p].xmltext#</cfoutput><br />
        </cfloop>
        <cfloop index="g" from="1" to="#ArrayLen(StateXML.state.group)#">
            <cfoutput>Person: #StateXML.state.group[g].xmltext#</cfoutput><br />
        </cfloop>
    </cfloop>
    </cfoutput>
    I suppose I could just put <try><catch> blocks around where I'm referencing <group> and if it doesn't exist, I'll just handle it that way - but that seems like such a hack.  Is there a 'real' way to determine if the node actually exists? 
    Thanks! 

    <cfif structKeyExists(StateXML.state, "group")>
        <cfloop index="g" from="1" to="#ArrayLen(StateXML.state.group)#">
            <cfoutput>Person: #StateXML.state.group[g].xmltext#</cfoutput><br />
        </cfloop>
    </cfif>

  • How to count number of xml nodes , with JSTL XML api?

    I am trying to count the number of nodes in the parsed xml by doing this:
    <x:out select="count($doc/Items/Item)"/>
    There are about 50 item nodes in the source xml, but I get the output as 0
    Is this syntax correct?
    I searched every where but couldn't find the xpath syntax to be used inside jstl xml tags, I was assuming that it's the same as the syntax used in xslt

    Thank you for your reply, sorry I wasnt very clear with my question.
    I want to count the number of nodes inside the jsp file , not inside the xslt file.
    My xml file is something like this for example:
    <?xml version="1.0" encoding="UTF-8"?>
    <DocumentRootNode>
    <Products>
    <Item>1</Item>
    <Item>2</Item>
    <Item>3</Item>
    <Products>
    </DocumentRootNode>
    I want the count of number of Item nodes , in the JSP file.
    I'm doing something like this in the JSP but it gives 0 instead of 3:
    <c:import url="source.xml" var="xml" charEncoding="UTF-8"/>
    <x:parse doc="${xml}" var="xml_doc"/>
    <x:out select="count($xml_doc/Products/Item)"/>
    null

  • Can't specify XML Schema root in MDM Syndicator

    Hello:  I am using MDM 5.5 SP3, and I am trying to use Syndicator to output multilingual XML product descriptions.  The XSD I am attempting to use is pasted below.
    When I attempt to specify the Destination Properties and select the XSD file I have loaded into the repository via the Console, I am unable to select the "Root" (it is grayed out).  I am unable to use the XSD in any way within Syndicator because the "OK" button is grayed out...I assume because Root has not been specified.
    Any suggestions?
    Thank you - Matt
    <?xml version="1.0"?>
    <xs:schema xmlns:xs="http://www.w3.org/2000/10/XMLSchema">
    <xs:element name="ProdDescription" maxOccurs="unbounded">
      <xs:complexType>
        <xs:sequence>
          <xs:element name="ProdCatalogNum" type="xs:string"/>
          <xs:element name="Description" type="xs:string" maxOccurs="unbounded">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="Language" type="xs:string"/>
                <xs:element name="Value" type="xs:string"/>
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:sequence>
      </xs:complexType>
    </xs:element>
    </xs:schema>
    I also tried this variant with no success.  Changes are <b>in bold</b> and notes are <u>underlined</u>.
    <?xml version="1.0"?>
    <xs:schema xmlns:xs="http://www.w3.org/2000/10/XMLSchema">
    <b><xs:element name="root">
      <xs:complexType>
        <xs:choice maxOccurs="unbounded">
          <xs:element ref="ProdDescription" />
        </xs:choice>
      </xs:complexType>
    </xs:element></b>
    <xs:element name="ProdDescription"> <u>previously: maxOccurs="unbounded"</u>
    <xs:complexType>
        <xs:sequence>
          <xs:element name="ProdCatalogNum" type="xs:string"/>
          <xs:element name="Description" type="xs:string" maxOccurs="unbounded">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="Language" type="xs:string"/>
                <xs:element name="Value" type="xs:string"/>
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:sequence>
      </xs:complexType>
    </xs:element>
    </xs:schema>

    I solved my problem:  here is the updated XSD:
    I believe it was mostly due to the <b>bolded</b> line:
    <?xml version="1.0"?>
    <b><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"></b>
         <xsd:element name="ProdDescription" type="ProdDescType"/>
         <xsd:complexType name="ProdDescType">
              <xsd:sequence>
                   <xsd:element name="ProdCatalogNum" type="xsd:string"/>
                   <xsd:element name="Description" type="DescriptionType" maxOccurs="unbounded"/>
              </xsd:sequence>
         </xsd:complexType>
         <xsd:complexType name="DescriptionType">
              <xsd:sequence>
                   <xsd:element name="Language" type="xsd:string"/>
                   <xsd:element name="Value" type="xsd:string"/>
              </xsd:sequence>
         </xsd:complexType>
    </xsd:schema>

  • How to create xml nodes based on a value

    Dear friends,
    I've a question about graphical mapping in SAP PI...
    How can I create XML nodes on the target side based on a value in a XML field on the source side.
    For example:
    This XML field on the source:
    <NO_OF_LINES>4</NO_OF_LINES>
    Must result on 4 Lines on the Target:
    <LINE></LINES>
    <LINE></LINES>
    <LINE></LINES>
    <LINE></LINES>
    So it's actually the opposite of the Count function...
    I appreciate your help,
    Thank you in Advance,
    Kind regards,
    John

    Hi ,
    Try this
    NO_OF_LINES---> count---> UDF---> LINE
    example :
    UDF Code :
    for (int i=0;i<var1[0];i++)
    result.addValue("");

  • Convertion of String to XML node using Xquery transformation in OSB

    How to convert string to XML node elementusing a built in function using Xquery transformation in OSB?

    check this out - http://www.javamonamour.org/2011/06/fn-beainlinedxml.html
    if in SOA (BPEL & Mediator) you can use oraext:parseXML.
    you should thoroughly analyse where to implement your requirement as some good practices advise to implement more complex logic in SOA and leave OSB to only connect to the services' endpoints.
    Hope this helps,
    A.

  • Check whether there is nodes inside a xml node

    I am trying a few different way, but i can't get the point,
    hope some expert can help me on this.
    eg:
    <product>
    <item>
    </item>
    </product>
    <cfscript>
    <!--- after xml parse to xmlElement --->
    if (xmlElement.product.item neq ""){
    writeOutput(xmlElement.product.item[1]);
    But this wont work for me, anyone know how to check whether a
    xml node contains child nodes or not?

    xmlSearch()?
    Adam

  • How we can get the output in excel format for Spawned programs?

    My requirement is to get the excel output for some of the programs (like -Adjustment Register, Applied Receipts Register). I am trying to achieve this by BI Publisher. But these programs has "Spawned" executable. And when I am changing the output type as"XML" I am getting below error in output-
    "XML Parsing Error: syntax error"
    Can anyne suggest how we can get an XML output and then excel output for Spawned programs?
    Thanks in advance,

    Hi,
    If I get it right, you want to convert RXi (Reports Exchange) reports such as Adjustment Register & Applied Receipts Register into XML Publisher. Normally, you need to change the "Output Format" of the program called by the "Spawned" program to 'XML' -- not the "Spawned" program itself.
    However, I believe RXi reports does not support XML output (atleast in 11i). It could only work on Text & Html format. Check on the metalink note below:
    432719.1 - RXi-Only Reports Generate XML Format Exception With No Output Setting the Output Format to XML
    Hope this helps.
    regards,..
    Rownald

  • Anyone know how i fix the fm2011 xml parsing error? Urgently need to find a fix before holidays

    Anyone out there know how i can fix the xml parsing error on football manager 2011? It's wrecking my excellent 4th season and even a delete and reinstall with new game hasn't worked

    Have you tried Windows Update in the Control Panel?
    Many times it will find the newest supported drivers for Hardware.
    Just be sure to install everything not just the Important ones.
    Let us know if this helps.

  • Can't change xml file

    I am trying to import files from an external drive. I was able to do the add file to library from the drive but whenever I reload itunes it expects the files to be on my external drive which I have removed. I tried to change the location of the files in the itunes music library xml file but everytime I bring up itunes it changes the file location back to the original file on the external hard drive. I physically copied the files from the external drive to my itunes directory but itunes refuses to let me manually change the xml file to reflect the new location. Does anyone have a clue as to how I can update the xml file to point to the itunes directory for these imported songs rather than pointing back to the external drive?

    Bart_Blommaerts wrote:
    2: I set the "&#235 ;" value myself ..The problem setting this value in your Java code is that ... &#235; cannot be used to escape anything in Java, it only can be used to escape characters in an XML file.
    This is why an XML parser will automatically translate this value for you when it parses the XML file. The dom4j Document object will never see this value and when you do a getText() the resolved value is returned.
    Instead in Java you should use either the '�' value (make sure to save your Java files as Unicode) or you could use the Java way to escape characters: \u00EB.
    I was satisfied with the "�" in my XML file ... but when I deployed the application to the webserver .. and generated an XML-file I read "��", which is definitely not what I want ..
    So on my local Tomcat5 server I get "�". On the SunWappserver I get "��".This seems to be a different problem. When you read the file, you will have to make sure to read the file with the encoding that it was saved in. This means that the editor that you use to read the file will have to be able to read files encoded using UTF-8 (Unicode).

Maybe you are looking for

  • Upgrading Windows CS4 to Mac CS5 - What is needed?

    I  called Adobe Cust Supt, and I wanted to verify on here what I think I heard from the customer service.  It was overseas and I could barely understand a word she was saying. Our company is moving from Windows network to Mac.  We purchased CS4 a few

  • Captivate Video in PDF Output Cropped

    Greetings: Using Captivate 3, I am trying to embed a training video inside a PDF version of a user manual. I followed the instruction on the Adobe Developer Connection "Adding Adobe Captivate movie clips to a PDF file" and deselected the borders in o

  • Nokia 5610 does not recognize memory card

    I have acquired a Nokia 1GB microSD memory card for Nokia 5610 d-1. But  the memory card is not recognized. In Nokia 6303 the same memory card is recognized. I have formatted them with this mobile phone. Nevertheless, the 5610 (v10.00) does not recog

  • How to record to dv tape?

    i have a Sony HVR-M15AU, and i know you can record to the tape via the firewire in... i'm just not sure how to go about doing that in premiere... is it at the capture area? the export area? in the time line? not sure.... running PrPro CC 2014

  • Number of rows to be displayed in Compensation Planning iView in ECM

    Hi Experts, I want to increase a number of rows to be displayed in the Compensation Planning iView in ECM from 5 to 10. How do I do that? Thanks! Anthony