Solved

XPathNavigator in C#

Posted on 2006-11-17
9
656 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Adding items to a C# list incrementally 5 82
JQuery Detecting page post back 6 34
C# LINQ 5 43
I'm looking for a dynamic length jQuery/javascript currency editor mask? 2 63
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

734 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