Solved

XPathNavigator in C#

Posted on 2006-11-17
9
654 Views
Last Modified: 2012-06-27
I am using C#

I have instance of XPathNavigator

Now, what is required to me is that

If XPathNavigator.Select("//errors");

Has the values or has the errors than it return no of nodes.

If errors node has no values, then it should return 0.

If XPathNavigator.Select("//errors");

Has the values or it is 1

Can I have the Full XML file in String?

Can anyone check my code for this if it is correct?

especially saving of XPathNavigator to XML as string

I will save this string in database thereafter.

My Code is below:

      public int isErrorExists(XPathNavigator nav)
        {

            XPathNodeIterator iterator = nav.Select("//errors");          

            int cnt = 0;

            while (iterator.MoveNext())
            {
                cnt++;
            }

            if (cnt!= 0)
            {
            string strXML = nav.InnerXml;
            
            // Now save strXML in Database.
          }
      }

Guide me the best way and if my way is correct or not.

Also please correct my code if it is not.

Thanks in Advance

Kind Regards,
0
Comment
Question by:dinesh_bali
  • 4
  • 2
9 Comments
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 17964350
XmlDocument FDocument = new XmlDocument();
FDocument.Load(FFileName);
XmlNodeList FTemp = FDocument.GetElementsByTagName(NodeName);

if(FTemp.Count != 0)
{
string strXML = FDocument.Innerxml;
       //Write to databse
}
0
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 17964356
i rewrote the code b'coz in ur logic u would have to loop through the iterator which is not necessry as u put it.

ur code will work..
0
 

Author Comment

by:dinesh_bali
ID: 17964403
Hi,

I will get XPathNavigator from Object.

Means I will use method which someone else has written will not written me XmlDocument  but it will return me XPathNavigator

So, I want to check the values from XPathNavigator only.

Your Code is using XmlDocument, which is not my requirement.

There for I wrote method, where I will pass XPathNavigator in my function and do the processes.

public int isErrorExists(XPathNavigator nav)

I hope now you are more clear about my requirement and help me better.

Awaiting your reply
Thanks in Advance
0
ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 17964494
public int isErrorExists(XPathNavigator nav)
        {

            XPathNodeIterator iterator = nav.Select("//errors");          


            if (iterator .Count != 0)
            {
          string strXML = nav.InnerXml;
         
          // Now save strXML in Database.
         }
     }
0
 

Author Comment

by:dinesh_bali
ID: 17964620
Thanks,

1) If I want all text in the node errors in a string

how we will do this

2) If I want the complete errors node then how we will get it

Many Thanks for your helping
0
 
LVL 29

Accepted Solution

by:
Gautham Janardhan earned 500 total points
ID: 17964668
public int isErrorExists(XPathNavigator nav)
        {

            XPathNodeIterator iterator = nav.Select("//errors");
          string strXML = "";
          if (iterator.Count!= 0)
          {  
            while (iterator.MoveNext())
            {
                strXml +=  iterator.Current.InnerXml;
            }    
          // Now save strXML in Database.
         }
     }

0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question