• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 189
  • Last Modified:

Read and retrieve value from a xml which has been stored in a database table column and the datatype is varchar

Hi,
    I have database (DB2) with column name (datatype varchar(6000)) xmlemployee where i store xml file info of the file created.
There is no problem in getting xml column from the database. The problem is i have to either loop through the xmlstring (xmlemployee) and get the salary, bonus and other fees from the xml.

<Salary xmlns='\http:\\www.mycompany.com\form\'>4000</Salary>
<Bonus xmlns='\http:\\www.mycompany.com\form\'>4000</Bonus>
Do i need to loop through to get the salary value of using dataset to get the value.
I tried with index of then i get confused that the salary amount may be 4to 10 digits then in that case i have to replace, replace many times if the salary digit is 2 or 3.

Could anyone help me with code sample how to retrieve the salary, bonus from the xml string.

Thank you.
 
0
aneethat
Asked:
aneethat
  • 2
1 Solution
 
lucky_jamesCommented:
Make use of XPathNavigator. If you have any file then load it in XPathDocument, else load the string xml into the XPathDocument and then get XPathNavigator from it and iterate.

Sample Code:

            xpd = new XPathDocument("Pages.xml");
            if (xpd != null)
            {
                XPathNavigator xpn = xpd.CreateNavigator();
                xpn.MoveToFirstChild();
                if(xpn.Name.Equals("user"))
                {
                    xpn.MoveToFirstChild();
                    xpn.MoveToFirstChild();
                    if (xpn.Name.Equals("Salary"))
                    {
                            String str = xpn.Value;
                    }

                    while(xpn.MoveToNext())
                    {
                        if (xpn.Name.Equals("Salary"))
                        {
                                String str = xpn.Value;
                        }
                    }
                }
            }
0
 
alain34Commented:
Hello aneethat,

Which programming language do you inted/expect to use to retrieve the data?

Regards,

alain34
0
 
lucky_jamesCommented:
here in my previous comment i assume the following schema:

<User>
        <Salary>50000</Salary>
       <Bonus>4000</Bonus>
</User>

Let me know if you have any doubt
0
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now