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


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

MSXML2 or XmlDocument ? using an union Expression in XPath 2

Posted By:      Posted Date: October 11, 2010    Points: 0   Category :.NET Framework
 


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




View Complete Post


More Related Resource Links

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


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.

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.

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

help with xpath expression needed

  

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


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

UNION ALL or CASE Expression?

  
Hi Frdz, i spent around 4 hours on this but i couldnt find answer, i want the result like

Rejects
---------------
somefilename1.txt - Rejected (and if no file then No from else expression(No - Invalid) - Query 1)
somefilename2.txt - Previous (and if no file then No from else expression(No - Valid) -Query 2)

I dont understand what do i do, do i use union all or case expression. plz help me with this.

QUERY1:
if exists (select NULL from table1 where Column1 = 'File1')
select distinct Column1 +'-'+ 'Rejected' as 'Rejects' from table1
where Column1 = 'File1'
else 
select 'No' as 'Invalid'

QUERY2:
if exists (select NULL from table1 where Column1 = 'File2')
select distinct Column1 +'-'+ 'Previous' as 'Rejects' from table1
where column1 = 'File2'
else 
select 'No' as 'valid'

Thanks

Manipulate XML data with XPath and XmlDocument (C#)

  
This link given a basic knowledge about XPath

Need Syntax To Make Results of LINQ Union Return Non-Generic Type

  

Hi.

I have the below SQL which works just fine:

SELECT     Message, CreateDate, AccountId, AlertTypeId
FROM       dbo.Alerts
UNION
SELECT     TOP (100) PERCENT Status, CreateDate, AccountId,
                          (SELECT     10 AS Expr1) AS AlertTypeId
FROM         dbo.StatusUpdates
WHERE AccountId = PassedInParameter
ORDER BY CreateDate DESC

I have been going about trying to convert the above into a LINQ method and am having problems with return types.
As the above SQL illustrates, I am querying two distinct LINQ tables - Alerts and StatusUpdates -
and then attempting to perform a Union on them. In order to do the union in LINQ, I have to have agreeing types. So, I
am using "var" to make the results of "alerts" and "updates" generic before the union.  

public IList GetStatusUpdatesAsAlertsByAccountId<T>(Int32 accountId)
        {
            using (WorkbookDataContext dc = _conn.GetCont

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

Asp to asp.net cant find Msxml2.XMLHTTP

  

Hi all i have this following code in asp and when i try this in .net it asks me to run in aspcompat=true mode which i dont want.
So i tried to DIM x as Msxml2.XMLHTTP but its not defined any suggestions on this. Thanks

xmlhttp = Server.CreateObject("Msxml2.XMLHTTP")
        On Error Resume Next
        xmlhttp.Open("POST", "https://xxxxx.cgi", False)
        xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
        queryString = "xxxRequestMode=X&xxxRequestData=" & Server.UrlEncode(xmlStr)
xmlhttp.Send(queryString)


 


[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