473,387 Members | 1,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

why doesn't this xpath expression work ?



I'm reading a csproj file trying to extract info via xpath and this first
one works fine

xmlNode =
xmlDoc.SelectSingleNode("/def:Project/def:PropertyGroup[1]/def:OutputType/text()",nsMgr);

but this one doesn't and the only change is the key name and that is
present. The xml is pasted below

xmlNode =
xmlDoc.SelectSingleNode("/def:Project/def:PropertyGroup[1]/def:AssemblyName/text()",
nsMgr);

I switch them around and run the second one first or even comment out the
first one and it still doesn't work (I mention that because I was reading
another post where someone was saying something about the node is removed
from the document and wouldn't be present for the second selectsinglenode,
not sure what thats about)

thanks

<Project DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>

<Configuration Condition=" '$(Configuration)' == ''
">Debug</Configuration>

<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>

<ProductVersion>8.0.50727</ProductVersion>

<SchemaVersion>2.0</SchemaVersion>

<ProjectGuid>{106C49F4-4260-4A70-A362-84AF2DA95766}</ProjectGuid>

<OutputType>Exe</OutputType>

<AppDesignerFolder>Properties</AppDesignerFolder>

<RootNamespace>WelcomeEmail</RootNamespace>

<AssemblyName>WelcomeEmail</AssemblyName>

</PropertyGroup>

--------------------------------------------------------------------------------
Apr 5 '07 #1
2 3136

"Coaster" <Co*****@Coaster.netwrote in message
news:%2***************@TK2MSFTNGP05.phx.gbl...
>

I'm reading a csproj file trying to extract info via xpath and this first
one works fine

xmlNode =
xmlDoc.SelectSingleNode("/def:Project/def:PropertyGroup[1]/def:OutputType/text()",nsMgr);

but this one doesn't and the only change is the key name and that is
present. The xml is pasted below

xmlNode =
xmlDoc.SelectSingleNode("/def:Project/def:PropertyGroup[1]/def:AssemblyName/text()",
nsMgr);

I switch them around and run the second one first or even comment out the
first one and it still doesn't work (I mention that because I was reading
another post where someone was saying something about the node is removed
from the document and wouldn't be present for the second selectsinglenode,
not sure what thats about)

thanks

<Project DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>

<Configuration Condition=" '$(Configuration)' == ''
">Debug</Configuration>

<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>

<ProductVersion>8.0.50727</ProductVersion>

<SchemaVersion>2.0</SchemaVersion>

<ProjectGuid>{106C49F4-4260-4A70-A362-84AF2DA95766}</ProjectGuid>

<OutputType>Exe</OutputType>

<AppDesignerFolder>Properties</AppDesignerFolder>

<RootNamespace>WelcomeEmail</RootNamespace>

<AssemblyName>WelcomeEmail</AssemblyName>

</PropertyGroup>


Actually both don't work, my mistake. I had them working when I did a
SelectNodes call, I guess I'm not understanding the xpath very well
>
--------------------------------------------------------------------------------


Apr 5 '07 #2
Ok, if none of them work, you probably forgot to add the namespace in your NamespaceManager

The top node defines this namespace

xmlns="http://schemas.microsoft.com/developer/msbuild/2003"

To query the nodes inside this namespace you need to specify the namespace in your XPath query. This is usually handled by a NamespaceManager which substitutes an alias you provide with the proper namespace in the query.

Before your first query try adding this line

nsMgr.AddNamespace("def", "http://schemas.microsoft.com/developer/msbuild/2003");

Both queries should then work, if not, please provide some more of your code for review.

--
Happy coding!
Morten Wennevik [C# MVP]
Apr 5 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: gimme_this_gimme_that | last post by:
I once downloaded a shareware program that allowed you to open an xml file, click on a text or an attribute, an then see the xpath expression that would fetch that data. The program didn't...
2
by: ree32 | last post by:
When I import an xml document in Visual studio and Genereate as schema from it, and create a dataset from it, it adds this line into to the root element of my xml file -...
19
by: David Thielen | last post by:
Hi; If there are no namespaces this works fine for me. But if the xml has namespaces, then I get either no node back or an exception. Here is the sample xml: <root xmlns="http://www.test.org"...
9
by: David Thielen | last post by:
Hi; I am sure I am missing something here but I cannot figure it out. Below I have a program and I cannot figure out why the xpath selects that throw an exception fail. From what I know they...
10
by: TR | last post by:
I'm trying the select a element based on values of two attributes. In the Xml doc i need to look at an attribute minVal and maxVal. if the Value I'm passing in in the xPath is greate than min...
3
by: MikeL | last post by:
I'm using .Net 2.0. I realize that this means XPath 1.0 (which is ridiculous). So here's a document that I have that's not on disk but held in a variable (I queried an Exchange appointment...
4
by: syed.akhlaq | last post by:
Hi, Does anyone know how can I validate XPath expressions using xsd schema? Thanks
2
by: arunairs | last post by:
Hi, Is there a way of validating and XPath? In this case , I am accepting an XPath from the user and I need to validate the XPath syntax. Is there a regular expression available that anyone can...
14
by: Mikhail Teterin | last post by:
Hello! What's would be the syntax for a query, which would allow me to get only the elements with non-empty text-nodes? For example, from: <a><b></b></a> <c/> <d><e>meow</e></d>
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.