XPath pb

Hi

In infopath, I use a XPath expression to get some nodes :

 var oEMailNodeList = XDocument.DOM.selectNodes("//Message/EMail");

My problem is that this method returns 0 items. Here is the DOM.xml property
:

<?xml version="1.0" ?>

<?mso-infoPathSolution productVersion=\"11.0.5329\" PIVersion=\"1.0.0.0\"
href=\"file:///C:\Documents%20and%20Settings\t-stevbe\Local%20Settings\Appli
cation%20Data\Microsoft\InfoPath\7ab6e8af39fc42e2\manifest.xsf\"
solutionVersion=\"1.0.0.9\" initialView=\"messagesList\" ?>

<?mso-application progid=\"InfoPath.Document\"?>

<dfs:myFields
xmlns:my="\"http://schemas.microsoft.com/office/infopath/2003/myXSD/2003-07-
24T09:51:34\"

xmlns:s1="\"http://microsoft.com/wsdl/types/\"
xmlns:s0="\"http://tempuri.org/\"
xmlns:dfs="\"http://schemas.microsoft.com/office/infopath/2003/dataFormSolut
ion\"

xml:lang="\"fr\">

<dfs:queryFields>

<s0:GetMessagesByUserName>

<s0:userName>EUROPE\t-stevbe</s0:userName>

</s0:GetMessagesByUserName>

</dfs:queryFields>

<dfs:dataFields>

<GetMessagesByUserNameResponse xmlns="\"http://tempuri.org/\">

<GetMessagesByUserNameResult />

<messages>

<Message>

<UserName>DOMAIN\user</UserName>

<EMail>user@domain.com</EMail>

<MessageTitle>Test</MessageTitle>

<MessageBody>etettete</MessageBody>

<MessageID>bd3d5156-3960-4074-a7f8-f75d35e61219</MessageID>

<MessageDate>2003-07-21T15:52:11.8770000+02:00</MessageDate>

</Message>

</messages>

</GetMessagesByUserNameResponse>

</dfs:dataFields>

</dfs:myFields>



Is the XPath expression correct ??

Note that the expression "//dfs:dataFields" return actually the right node,
but the expression "//dfs:dataFields/GetMessagesByUserNameResponse" return 0
items.



Thanks for any help !



Steve


0
7/24/2003 2:06:03 PM
dotnet.xml 7266 articles. 0 followers. Follow

1 Replies
936 Views

Similar Articles

[PageSpeed] 12

Steve B. [Labo.Net] wrote:


> In infopath, I use a XPath expression to get some nodes :
> 
>  var oEMailNodeList = XDocument.DOM.selectNodes("//Message/EMail");


> <GetMessagesByUserNameResponse xmlns="\"http://tempuri.org/\">
> 
> <GetMessagesByUserNameResult />
> 
> <messages>
> 
> <Message>


> Is the XPath expression correct ??
Nope. See yourself - Message element is in "http://tempuri.org/" namespace, 
while //Message expression selects Message elements in null namespace.
Read about namespace issues in selectNodes method documentation.
-- 
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

0
oleg7603 (294)
7/24/2003 6:33:16 PM
Reply:

Similar Artilces:

Getting a specific parent of any node via xpath navigation
I am storing my site structure as such: <menuItems> <menuItem> <pageID>1</pageID> </menuItem> <menuItem> <pageID>2</pageID> <menuItem> <pageID>4</pageID> <menuItem> <pageID>5</pageID> <menuItem> <pageID>6</pageID> </menuItem> </menuItem> </menuItem> </menuItem> <menuItem> <pageID>3</pageID> ...

XPath
Using XPath I am querying parts of XML document, " get quoted by \ - is it possible to specify not to quote " with \? <RootElement> <Element Attribute="SomeValue" /> </RootElement> XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(fileName); XmlNode xmlNode = xmlDoc.SelectSingleNode("//RootElement/Element") Print xmlNode.OuterXml <Element Attribute=\"SomeValue\"/> where I was expecting to get <Element Attribute="SomeValue"/> TIA Dennis wrote: > Using XPath I am querying parts of XML document,...

XPath pb
Hi In infopath, I use a XPath expression to get some nodes : var oEMailNodeList = XDocument.DOM.selectNodes("//Message/EMail"); My problem is that this method returns 0 items. Here is the DOM.xml property : <?xml version="1.0" ?> <?mso-infoPathSolution productVersion=\"11.0.5329\" PIVersion=\"1.0.0.0\" href=\"file:///C:\Documents%20and%20Settings\t-stevbe\Local%20Settings\Appli cation%20Data\Microsoft\InfoPath\7ab6e8af39fc42e2\manifest.xsf\" solutionVersion=\"1.0.0.9\" initialView=\"messagesList\" ?> <?...

How to pass a Nodeset to an XPath extension function?
I am using the .NET framework v2.0.40607 with Visual C# Express and I would like to create some custom XPath functions to use directly in a XSLT stylesheet. I called System.Xml.Query.XmlArgumentList.AddExtensionObject(string, object) to register the functions I've written. The functions that take a String, Boolean or Number parameter work perfectly. However, I do not know how to create a function that will accept a Nodeset as a parameter. I tried writting a function taking a XPathNavigator object, but it does not work for all XPath queries that return a Nodeset: I get an error &qu...

XPath Validation
I'm looking for a way to Validate an XPath prior to executing the expression, without using a try catch clause. For example: I'm looking for something that would tell me that "\some/Xpath\to\Node" is invalid... Any Ideas? Hi, As far as I know, the .NET framework could not validate XPath directly with class library. The only thing we can do is to use try/catch block. Or you can try to find some 3rd-party tool such as XML spy to validate it. HTH. Kevin Yu ======= "This posting is provided "AS IS" with no warranties, and confers no rights." Thanks K...

Tricky XPath query
Hi all, I've just changed the structure of my XML file and now I need to construct an XPathNavigator object that uses tags from two different levels in the XML file. For example: <someTag> <innerTagA> <innerInnerTagA> <innerInnerInnerTagA> Some Data That Belongs Here </innerInnerInnerTagA> <innerInnerInnerTagB> Some Data that Belongs More Specifically Here </innerInnerInnerTagB> </innerInnerTagA> <innerInnerTagB> <innerInnerInnerTagZ> This Data should real...

Xpath with namespaces
Hello Everyone, I am having an issue with xml and namespaces, at least I think it is namespaces. When I use namespaces, I cannot use SelectSingleNode / SelectNodes as they always return 0/Nothing respectively. Anyone have any thoughts? Thanks in advance VB.Net 2005 WinXP Sp2 Test code: Dim objXML As System.Xml.XmlDocument 'Test XML 1 ==> Always returns 0 objXML = New System.Xml.XmlDocument objXML.Load(Application.StartupPath & "\xmlfile1.xml") MsgBox(objXML.SelectNodes("top/middle").Count) 'Test XML 2 ==> Always re...

xpath??
Hi, I am very new to xml. I have a datatable I need to group by and was suggested that xml and xpath might be the way to go. I converted the datatable to xml but don't know what to do next. Can anyone point me to the right direction. This is what I am trying to do: - have datatable (~300k rows and 5 cols) - need to group by column1(string catagory) and column2(date) - display the totals by column1 and column2 in datagrid. Any help is appreciated. Thanks. The advice to convert the database to XML was clearly a bad joke. RDBMSes are best at what they can do best -- work with relational da...

Sorting with XPATH
Given an XML node List with the individual nodes looking like the following, what kind of XPATH statement can I use to sort the nodes by element F8 and inside F8 by element F3? <OffNetworkRequestPackage> <Transaction> <OffNetworkRequest> <OffNetworkData> <UserEmail>loretta.pelisserok@getronics.com</UserEmail> <AdminEmail>NoEmail</AdminEmail> </OffNetworkData> <xxirequest> <function uuid="SBPProcess" name="CBICashCheck" bpname="TellerStd"/> </xxirequest> <TF&...

XPath and namespaces
Hi; First off, I think I still do not understand exactly how we are supposed to handle namespaces when doing xpath queries under .NET so I may have some bad assumptions here. As I understand it, we need to set the namespaces on an XmlDocument - the ..NET libraries do not read it from the xmlns:... attributes in the xml. In our case we have to handle xml our customers will pass to our library so we do not know up front what namespaces will be in there or how they are set up. So we do the following: private void SetNamespace(XPathNavigator nav) { XPathNodeIterator list = nav.Select...

Tricky XPath query
Hey all, I've attempted to simplify my question (or at least the XML that is part of my example in my question): I have the following XML: <A> <B><C><D> I want to query the data in this node for the element B </D></C><E> I also want to query the data in this node for the element B </E> </B> <B><!--Additional data for another B element--> </B> </A> My idea is to do something like this: --------------------------------------------------- Dim nav As XPathNavigator = doc.CreateNaviga...

XPath with namespace
Hello all, I am working on an Add-in to the .NET framework using C#. I wanted to search the XML document using XPath but failed. The XML is like this: <unit xmlns="http://www.some.info/srcML" xmlns:cpp="http://www.some.info/srcML/cpp"> <aaa>something</aaa> </unit> The code I am using is as follows: XPathNavigator nav; XPathDocument docNav; XPathNodeIterator NodeIter; string fname="sth.xml"; docNav = new XPathDocument(@fname); nav = docNav.CreateNavigator(); nav.Evaluate(input); NodeIter = nav.Select(input); It works fine if there is n...

XMLnodelist and XPATH Problem
I am having a problem selecting nodes using the XMLnodelist Selectnodes using XPATH when I use XML SPY is successfully queries but when is use VB.net it comes up with nothing. Here is my code Dim nodess As XmlNode nodess = myNode.SelectSingleNode("//Web[@Url= 'http://localhost']") If nodess Is Nothing Then SQLrw.Delete() End If nodess = Nothing The myNode Properites ------------------------------------------------------------------------------------------------ {System.Xml.XmlElement} [System.Xm...

What is the Xpath
Hello, Thanks for the response Oleg. Now I need to know few answers. How do I get the value of a node using the xpath. I want the value of the MessageID and ResultCode from secondxml. And using this I want to delete the Child Nodes in the firstxml document. I am using the fowllowing code but the ni.current.value has values of all nodes in the file. I am confused. XmlDocument doc = new XmlDocument(); doc.Load("Firstxml.xml") hDocument doc2 = new XPathDocument("second.xml"); XPathNavigator nav = doc2.CreateNavigator(); foreach (XmlNo...

Get attributes from XmlSchema for specific Node referenced by Xpath
I have a XSD loaded into a XmlSchema class. I need to retrieve the attribut names for/under a specific node in this schema, and I have the full xpath for the node in the schema. How do I do this? I'm not sure I should use the XmlSchema class to load the XSD. Regards Paw ...

XPath string
Hi, I want to get the node with text=”{123}”. 1/ The following statement works fine: XmlNode wksNode = parentNode.SelectSingleNode("child::wks[text()='{123}']"); 2/ When I try to use a variable for the value of text, it doesn’t work anymore: string str = "child::wks[text()='" + myText + "']"; XmlNode wksNode3 = parentNode.SelectSingleNode(str); What is wrong? The variable str is exactly the same like the string used within the function SelectSingleNode in case 1/ Thanks for help, Lubomir Lubomir wrote: > When I try to use a varia...

XPath and SQLXML
I have the following XSD created in VS.NET 2003: <?xml version="1.0" encoding="utf-8" ?> <xs:schema id="ReferralSchama" targetNamespace="http://test.org/Referral" elementFormDefault="unqualified" xmlns="http://test.org/Referral" xmlns:mstns="http://test.org/Referral" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> <xs:complexType name="ReferralType"> <xs:sequence> <xs:element name="nReferralId" msdata:...

Problem selecting a node with XPATH if attribute value contains backslashes
VB6, MSXML 3.2 installed: Q1. I am having a problem selecting nodes with XPATH expressions when an attribute values contain backslashes (\\) in as part of its value: For example the following statement fails to find a node (even though one exists in the XML) if the value of the LDAPServerURL attribute is \\LocalServer but works if the value is "LocalServer". Set xmlElement = _ xmlConfigFile.documentElement.selectSingleNode("Facility[@LDAPServerURL='" & <SomeValue> & "']") I assumed that anything inside the '' was treated as a li...

XPath #4
This is a multi-part message in MIME format. ------=_NextPart_000_0016_01C44593.E9775F00 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi, I am new to XPath and I am stuck with an expression. I would like to = select all servers which the user subscribed to. Here is my XML: <forums> <forum> <name>AAA</name> <subscribed>1</subscribed> </forum> <forum> <name>BBB</name> <subscribed>0</subscribed> ...

xpath syntax
I have the following xml: <?xml version="1.0" ?> <course> <globalProperties> <externalMetadata> <source>ADL</source> <model>ADL SCORM 1.0</model> </externalMetadata> </globalProperties> <block id="B1"> <identification> <title>Yes/No Questions</title> <description>This course has one lesson</description> <labels> <curricular>MODULE</curricular> <developer>Me</developer> </labels> </identification&g...

XPath resource
hi, i've started working on xml but its location-path subject is too confusing. any good reference on web or book ? thanks ...

XPath Request
Hi, How can i get all the nodes with attribute Name = "Publisher" or Name="Administrator" using XPath query and C# for this xml doc? <GetRoleCollectionFromUser xmlns=\"http://schemas.microsoft.com/sharepoint/soap/directory/\"> <Roles> <Role ID=\"1073741826\" Name=\"Reader\" Description=\"....\" Type=\"2\" /> <Role ID=\"1073741827\" Name=\"Publisher\" Description=\"....\" Type=\"3\" /> <Role ID=\"1073741828\" Name=\"Adm...

xpath for children
Hi all, Following is a part of an Xml document I am having problems with. I have a XmlNode variable in my C# application that referes to the mytable node of the following Xml. Now I need to get all children of mytable node from the ns0 namespace(myfield1 and myfield2 in this case) using the XmlNode object. I need a help with Xpath query to achieve this. Do you think the following statement would work? mytablenode.SelectNodes("descendant::ns0:*",mynamespacemanager); <ns0:mydataset> <ns0:mytable> <w:p> <ns0:myfield1>value</...

XPath questions
foreach(XmlNode node in xdoc.SelectNodes("//rss:item",xNsMgr)) { ... Read from node ... } How do I do the above using XPathNavigator? Is it better to compile an expression that run it directy when I'm using it only once? Are there performance advantages to XPath over XDoc*.Select* ? Ayende Rahien wrote: > foreach(XmlNode node in xdoc.SelectNodes("//rss:item",xNsMgr)) > > { > > .. > > Read from node > > .. > > } > > How do I do the above using XPathNavigator? XPathExpression expr = navigator.Compile("//rss:...

Xpath For All Values
Trying to figure out how to do an xpath that has all values equal to 0. //Record/AccidentIncome[.=0] I know this will find ANY instance where AccidentIncome = 0, but I need to determine if ALL nodes that have //Record/AccidentIncome equal to 0. Stated another way, I cannot figure out how to do the opposite - determine if any node has a value greater than zero, which is easy //Record/AccidentIncome[.>0] - but then use a keyword like not to reverse it and get a true statement. So if I have 2 nodes, and one of them has AccidentIncome = 5000, I wish this statement would become true, bu...