.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Kaviya Balasubramanian
Imran Ghani
Post New Web Links

help with xpath expression needed

Posted By:      Posted Date: October 07, 2010    Points: 0   Category :ASP.Net
 

I get an "Object reference not set to an instance of an object." with the following:

XML document
<response>

<lst name="facet_counts">
<lst name="facet_queries"/>

<lst name="facet_fields">

<lst name="hasphoto">
<int name="true">4</int>
<int name="false">2</int>
</lst>

</lst>
<lst name="facet_dates"/>
</lst>
</response>


XPath expression:
objXML.SelectSingleNode("response/lst[@name=""facet_counts""]/lst[@name=""facet_fields""]/lst[@name=""hasphoto""]/int[@name=""true""]").Value
OR
objXML.SelectSingleNode("response/lst[@name=""facet_counts""]/lst[@name=""facet_fields""]/lst[@name=""hasphoto""]/int[@name=""true""]").Innertext

But when I test it here: http://www.xmlme.com/XpathTool.aspx

The correct value (4) is returned...:s




View Complete Post


More Related Resource Links

Help needed on XPath Error: System.Xml.XPath.XPathException: Expression must evaluate to a node-set.

  
Im trying to determine if a value already exists in an XML file. In this case I want to know if there's a node "id" with value 3. But I cant figure out how...XML:<root><data><compare><locations><id>3</id><id>5</id></locations></compare></data></root>XSL:xmldoc.SelectSingleNode("//root/data/compare/locations/id=""3""")Error:XPath Error: System.Xml.XPath.XPathException: Expression must evaluate to a node-set.

xmldatasource and xpath expression evaluation

  
Hi, I am working with XMLdatasource and trying to consume a XML file. Now problem is there are scenarios when a link is not available in the xml file. Like in the e.g. below: <a href='<%# XPath("link") %>' >  </a>  say "link" can or cannot be there in the file. Now when "link" is missing, this expression throws exception. How can I handle this exception so that it continues loading page normally or can I check "link" existence somehow? Thanks.

XPath expression not working for Google Maps return XML

  
I have this XMLdocument:<kml><Response><name>3051,netherlands</name><Status><code>200</code><request>geocode</request></Status><Placemark id="p1"><address>3051 Rotterdam, The Netherlands</address><AddressDetails Accuracy="5"><Country><CountryNameCode>NL</CountryNameCode><CountryName>Nederland</CountryName><AdministrativeArea><AdministrativeAreaName>Zuid-Holland</AdministrativeAreaName><Locality><LocalityName>Rotterdam</LocalityName><PostalCode><PostalCodeNumber>3051</PostalCodeNumber></PostalCode></Locality></AdministrativeArea></Country></AddressDetails><ExtendedData><LatLonBox north="51.9497984" south="51.9402954" east="4.4907255" west="4.4656367"/></ExtendedData><Point><coordinates>4.4767883,51.9458650,0</coordinates></Point></Placemark></Response></kml>I used this site: http://www.xmlme.com/XpathTool.aspxwhere I enter the expression: "kml/Response/Placemark/Point/coordinates"I then get the right value. HOWEVER, when I place this code in .NET, the xpath expression returns nothing:req = HttpWebRequest.Create("http://maps.google.com/maps/geo?output=x

MSXML2 or XmlDocument ? using an union Expression in XPath 2

  


Hallo, I'm using XPath for a long time by MSXML, now I tested some xml access with XmlDocument and have a problem with using XPath2.
 

This one works:

DOMDocument doc2 = new MSXML2.DOMDocument();
MSXML2.doc2.loadXML(xmlText);
MSXML2.IXMLDOMNode node = doc2.selectSingleNode("bla1/bla2/(ytype|xtype)");



This one works not:

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlText);
XmlNode node = xmlDoc.SelectSingleNode("bla1/bla2/(ytype|xtype)");


Is there any explanation? Which class should I use in .NET for XPath 2 XML access ?

Best regards

Roy


MSXML2 or XmlDocument ? using an union Expression in XPath 2

  


Hallo, I'm using XPath for a long time by MSXML, now I tested some xml access with XmlDocument and have a problem with using XPath2.
 

This one works:

DOMDocument doc2 = new MSXML2.DOMDocument();
MSXML2.doc2.loadXML(xmlText);
MSXML2.IXMLDOMNode node = doc2.selectSingleNode("bla1/bla2/(ytype|xtype)");



This one works not:

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlText);
XmlNode node = xmlDoc.SelectSingleNode("bla1/bla2/(ytype|xtype)");


Is there any explanation? Which class should I use in .NET for XPath 2 XML access ?

Best regards

Roy


How to retrieve conditional XML data using XPath Expression

  
I have a XMLDataSource somewhat like:
<bookstore>
 <author>author1</author>
 <publication>publication1</publication>
 <book>
  <genre>Thriller</genre>
  <name>ABC</name>
 </book

Help needed with ISNULL Expression

  

I'm hoping someone can help me here.  I'm new to using the Derived Column Transformation Editor, and I have the task of tranforming a DB2 decimal column to a date SQL date column.  I already converted it to a string column, because I figured the best way to change it from their wacky way of dating to the correct way is through string manipulation.  The date format for DB2 is 1yymmdd (that's right, there's a 1 in front of it...don't ask me why, lol)

So I have the string format all correct.  This is the BASE expression;

SUBSTRING([Copy of ARRIVALDATE],4,2) + "/" + SUBSTRING([Copy of ARRIVALDATE],6,2) + "/" + SUBSTRING([Copy of ARRIVALDATE],2,2)

The result of the BASE expression is a date format; mm/dd/yy, but now I have a problem.  If the item has yet to arrive, it is null, and I cannot convert it to a date because if it is null I end up with two slashes.  (//).  Okay...so I tried this;

ISNULL([Copy of PRINTEDDATE]) ? " " : (SUBSTRING([Copy of PRINTEDDATE],4,2) + "/" + SUBSTRING([Copy of PRINTEDDATE],6,2) + "/" + SUBSTRING([Copy of PRINTEDDATE],2,2))

The problem is, I STILL end up with just two slashes even if it is null.  Could anyone help me in correctly forming this expression so that a null value will return a n

Regular Expression needed for 10, 11, or 12-digit number in code behind

  

Hi there,

I am in need of validating a number that can be 10, 11, or 12 digits in lenght.  It cannont contain any spaces, symbols, or letters.  I have to do this in the code behind of my web form.  I am using C# ASP .NET 2.0. 


Response.BinaryWrite help needed

  

Hi all

Im new to .NET and stuck now, so i hope anyone can help my with my problem.

I have a MS SQL database where i have stored some documents as Binary data. I cant figure out how to retrieve them and show/download them in my browser.

I found some guides online and have try to put something together.


Download.aspx.cs:

private void Write()
 {
 int id = 0;
 string strID = Request.QueryString["id"];
 int.TryParse(strID, out id);

 var db = new ModelDataContext();
 var doc = db.DocumentDatas.Where(x => x.ID == id).FirstOrDefault();

 byte[] byteArray = File.ReadAllBytes(doc);

 Response.BinaryWrite(byteArray);
 }

How do i fill the byteArray with the data?

Thanks in advance :)

/Ryan


xpath issue

  

Hi i am using xpath to loop through each node,

the xml is below i can get the value of "link" but i cant get the thumbnail value, have you got any ideas how i can do this, my code is below.

Thanks

<item>

     <link>test 1</link>
     <media:thumbnail url="http://test.com/image.jpg" height="75" width="75" />

</item>

<item>

     <link>test 2</link>
     <media:thumbnail url="http://test.com/image.jpg" height="75" width="75" />

</item>



public void FindLinks(XPathNavigator p_xPathNav, DataTable dt)
        {           
            //run the XPath query
            XPathNodeIterator xPathIt = p_xPathNav.Select("//item");

            //use the

help needed: Ldap User authentication using userDN and password

  

Hi

Is it possible to authenticate a user using userDN and password? If so, then tell me the syntax.So far i have tried to authenticate using username and password from my c# code using directoryentry which takes the parameters like domainname,username and password. But i need to authenticate using Userdn and password.



helped needed: ASP LDAP authentication failed in IE 8

  

I use the following code to do the user authentication through Active Directory using LDAP.

try
{
entry = new DirectoryEntry("LDAP://" + server, user_name, password);
if (!string.IsNullOrEmpty(entry.Name))
{
EmployeeNetId = entry.Username.Substring(0, 3);

// Retrieve EmployeeId, and Employee Full Name
GetEmployeeId(EmployeeNetId);
}
}
catch
{
EmployeeId = -1;
}

It works for Chrome, Firefox with no problem. But with IE 8, it works sometimes, and failed on some computers. When it failed, I figured that I need to check SSL 2.0 in IE 8 Internet Options.  It's weird because in those computers that IE 8 works, SSL 2.0 is also unchecked.

Am I using some deprecated method? Or How do I specifiy the SSL version options in the LDAP connection?


[How??] Lamda expression with ByRef parameter

  

How to write lamda expression with ByRef/ref parameter in c# ??

The code below causing syntax error:

item.OnAction = (p1, p2, ref p3) => {
   .....
   .....
   return true;
};


item.OnAction = (p1, p2, & p3) => {
   .....
   .....
   return true;
};



Express Yourself: Encoding Videos Using Microsoft Expression Encoder 3 SDK

  

Video on the Web involves huge amounts of data. Learn the best way to manage and move that data with the help of Microsoft Expression Encoder 3.

Adam Miller

MSDN Magazine June 2010


Security Briefs: Regular Expression Denial of Service Attacks and Defenses

  

Microsoft security expert Bryan Sullivan believes denial-of-service blackmail attacks will become more common as privilege escalation attacks become more difficult to execute. He demonstrates how to protect your apps against regular expression DoS threats.

Bryan Sullivan

MSDN Magazine May 2010


Silverlight: Create Animations with XAML and Expression Blend

  

In this excerpt from his upcoming book, Laurence Moroney explains the basics of Silverlight animation and the animation tools available in Expression Blend.

Lawrence Moroney

MSDN Magazine August 2008


Silverlight: Create a Custom Expression Encoder Publishing Plug-In

  

Laurence Moroney demonstrates how to employ the Expression Encoder plug-in APIs by building and debugging a simple FTP upload plug-in.

Laurence Moroney

MSDN Magazine February 2008


Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend