Solved

XPathNavigator in C#

Posted on 2006-11-17
9
659 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

622 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