dinesh_bali
asked on
XPathNavigator in C#
I am using C#
I have instance of XPathNavigator
Now, what is required to me is that
If XPathNavigator.Select("//e rrors");
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("//e rrors");
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(XPathNavigat or 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,
I have instance of XPathNavigator
Now, what is required to me is that
If XPathNavigator.Select("//e
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("//e
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(XPathNavigat
{
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,
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..
ur code will work..
ASKER
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(XPathNavigat or nav)
I hope now you are more clear about my requirement and help me better.
Awaiting your reply
Thanks in Advance
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(XPathNavigat
I hope now you are more clear about my requirement and help me better.
Awaiting your reply
Thanks in Advance
public int isErrorExists(XPathNavigat or nav)
{
XPathNodeIterator iterator = nav.Select("//errors");
if (iterator .Count != 0)
{
string strXML = nav.InnerXml;
// Now save strXML in Database.
}
}
{
XPathNodeIterator iterator = nav.Select("//errors");
if (iterator .Count != 0)
{
string strXML = nav.InnerXml;
// Now save strXML in Database.
}
}
ASKER
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
FDocument.Load(FFileName);
XmlNodeList FTemp = FDocument.GetElementsByTag
if(FTemp.Count != 0)
{
string strXML = FDocument.Innerxml;
//Write to databse
}