.NET Framework - using the XPath ID command

Asked By p_le_sueur_
21-Jun-07 08:01 AM
Dear All,

Can anybody offer me advice or examples on using the "id"
command in XPath? (within InfoPath!); and also confirm that
I am trying to use the correct function for what I want to
accomplish?

I am experimenting with InfoPath for a project whereby I
set conditional formatting for a text field based on the
value of a dropdown field.

The dropdown field is referred to by name within a second
text field, allowing the actual dropdown referenced to
change at runtime.


The resultant XML from my experimental template looks like
this:



The process is this:

The my:txtbox1 control in the InfoPath template will have a
conditional format on it which will pick up the name of a
control (my:DDLChoice) from the my:TextBox2 control, and make
my:TextBox1 visible if DDLChoice is "Yes" or invisible if it
is "No".


I am having problems with the expression in the conditional
formatting on TxtBox1; what I have so far is:


id(concat("../my:", ../my:TxtBox2)) = "No"

But this gives the following error:

InfoPath cannot open the following view: View 1
The XSL transform for the View XSL failed.

This name may not begin with the '.' character:

-->.<--./my:


I have run another test where I have placed the following expression
into the default value for TxtBox1 (and removed the conditional
formatting):

concat("../my:", TxtBox2)

When I preview the form I get the following in TxtBox1:

../my:DDLChoice

Which looks to me like it is picking up the fieldname correctly;
however;
If I try and add the id function around it:

id(concat("../my:", ../my:TxtBox2))

I get this error when validating the function:

This name may not begin with the '.' character:

-->.<--./my:DDLChoice


I'm obviously missing something with regard to the "id" function
(undoubtedly due to my lack of experience with XPath), can
anybody help, or provide any useful examples??

Thanks in anticipation,

Paul Le Sueur.
InfoPath
(1)
DDLChoice
(1)
KeyID
(1)
XPath
(1)
Höhrmann
(1)
Mannheim
(1)
SomeId
(1)
Björn
(1)
  Martin Honnen replied...
21-Jun-07 09:23 AM
An ID value in XML is not allowed to start with a dot '.' so that is why
you get the error message as the argument you pass to the id function
'../my:DDLChoice' starts with a dot.

It is not clear to me what you want to achieve, using the id function
makes sense if you have a DTD or schema defining ID values, otherwise
not. The snippet of XML your post shows does not refer a DTD or schema
at all so it is not clear whether using the id function makes any sense.


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
  p_le_sueur_ replied...
21-Jun-07 10:10 AM
Hi Martin,

Thanks for your reply!

My understanding of the id function was that it would allow me to
return the value of the field named within the id command, so in
the example from my original posting:

my:TxtBox2 contains a string with name of my dropdown list

my:TxtBox1 contains a default value function to pick up the value
from the dropdown list named in my:TxtBox2. So this would be:

id(concat("../my:", ../my:TxtBox2))

where concat("../my:", ../my:TxtBox2) is concatenating the string

If I run this concat command on it's own it returns

so the id command should be looking for the value in the
DDLChoice field, effectively through the following syntax:
id("../my:DDLChoice")
However, this doesn't work!!

I hope this makes sense, and explains a bit more about what I am
trying to do...

Thanks again!

Paul Le Sueur.
  Martin Honnen replied...
21-Jun-07 10:22 AM
The id function is defined here:
so
id("someId")
returns a node set with the element having the id 'someId'. For that to
work there needs to be a schema or DTD declaring attributes of type ID.




The ID type is defined here:
A valid ID value cannot start with a dot so that is why you get an error
when passing in "../my:DDLChoice".

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
  Bjoern Hoehrmann replied...
21-Jun-07 10:27 AM
* p_le_sueur_1@hotmail.com wrote in microsoft.public.xml:

The id(...) function returns an element with the specified ID. This is a
globally unique name an element can carry in an attribute if it has been
declared as being of type "ID" using a schema, DTD, or other means. It's
not suitable to retrieve values of any kind, generally, you have to use
an expression that evalutes to a specific node and retrieve its string
value; often this happens implictly.

I recommend you read up on namespaces. In XML documents, attributes and
elements have names consisting of two components, the namespace name and
the local name. If you have <my:example xmlns:my='http://...'/>, that is
an { 'http://...', 'example' } element, not a "my:example" element. To
use namespaced elements and attributes in XPath expressions, you have to
declare a prefix for the namespace name and specify the prefix in the
expression.

As an example, string(/.../my:Group1/my:DDLChoice) would evaluate to the
string "Yes" as that is the elements value in your initial example. For
this to work, you have to tell the processor 'my' stands for something
else, for whatever you have specified in the xmlns:my='...' declaration
in the document.
--
Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
help
Xpath and Sorting .NET Framework How do I create an xpath expression to return a sorted nodelist? I need the sort to be by the attribute NodeNameList.SelectNodes("Name[@lastName = sorted"] or something to this effect -Lou Xml Discussions System.Xml.XPath.XPathNodeIterator (1) System.Xml.XPath.XPathNavigator (1) System.Xml.XPath.XPathDocument (1) System.Diagnostics.Debug.WriteLine (1) NodeNameList.SelectNodes (1) XmlCaseOrder.LowerFirst (1) XPathNodeIterator (1 the XPathDocument by specifying the path to Books.xml. Dim xmldoc As New System.Xml.XPath.XPathDocument(ElectionData.DataFile) 'Create XPathNavigator. Dim nav As System.Xml.XPath.XPathNavigator = xmldoc.CreateNavigator() 'Compile the XPath query expression to select all the Title elements. 'The Compile method of the XPathNavigator generates
INFOPATH issues .NET Framework I started a purchase order project that will allow a few employees to access a purchase order over the network. They will each be running infopath as their client. Each employee also has MS Access 2003 or 2007 installed on their PC's. I'm new at INFOPATH but I easily created a purchase order form on my own development PC called c connector (System DSN) called VendorsTBL which is the same name as the old one, yet infopath would complain with the following long error message: InfoPath cannot open the form. To fix this problem, contact your system administrator. Form template: file TGSPurchaseOrder4.xsn The form template is trying to access files and settings on your computer. InfoPath cannot grant access to these files and settings because the form template is not fully this problem? I already put an incident through the phone support but I was told InfoPath doesn't have a wait queue, but instead they only offer call-back phone support say the least. Do you recommend I use a web-based approach instead of the infopath-msaccess one? If so, is there an easy way to translate the infopath form to
An old WORD form imported to InfoPath .NET Framework I imported an old Word form into Infopath. After making numerous changes / enhancements to the form, using InfoPath 2007, I have saved the form in both InfoPath 2003 and 2007. For both versions, I find that I am unable perform some other schema. 2. I have chosen browser compatibility to open either in a browser or in InfoPath. I have 3 design checker errors telling me that rich text formatting options are not supported. I have other browser enabled InfoPath forms, that I created from scratch, that use rick text formatting. 3. I am unable it does not show. 4. I am unable to set the form to landscape mode. InfoPath throws an error that it has encountered an error and that the operation has failed assist as I really do not want to create this form from scratch! .NET Discussions InfoPath 2007 (1) InfoPath 2003 (1) InfoPath (1) Office (1) Word (1) Color (1) Deb (1
me the follwing task and 3 weeks to complete it. Implement a POC application in InfoPath Services 2007 based on at least 3 clinical forms. The application will be coded in do other developers think? How long would it take an experienced C# programmer to leran InfoPath 2007 and do this? C# Discussions Visual Studio .NET (1) InfoPath 2007 (1) InfoPath (1) WebService (1) ADO.NET (1) VB.NET (1) VB (1) Component (1) Helen, You weeks is an unreasonable amount of time to do it in. I've never used InfoPath 2007 or the Enterprise Library and I'm not a C# programmer. It's a short time. The form data will be stored as an XML data type and the InfoPath form will use it as the data source. Is this a sensible way of doig an entirely new language (C#), a new framework (asp.net), and 2 new libraries / technologies (Infopath and Enterprise Library 2.0). Doubly so if your background is VB windows apps - there time frame, and the only thing I'd have to learn in your list is InfoPath. The real question here is how do you manage expectations of a manager who either
Scripting problem creating function for InfoPath .NET Framework I am trying to create a date function in InfoPath using JScript I need to create a function that will add one day to a scripting, but from the articals I have read the only way to do this in InfoPath 2003 is to script it. What I am trying to do is. . . I have a any idea = 92s, pointers, references or anecdotes even would be greatly appreciated. Thanks JScript Discussions InfoPath 2003 (1) InfoPath (1) SonOfRFC1036 (1) ASP.NET (1) FAQish (1) JavaScript (1) JScript (1) Stockton (1) I am trying to create a date function in InfoPath using JScript I need to create a function that will add one day to a scripting, but from the articals I have read the only way to do this in InfoPath 2003 is to script it. What I am trying to do is. . . I have a to me. Before a reply, quote with "> " or "> " (SonOfRFC1036) keywords: Scripting, problem, creating, function, for, InfoPath description: I am trying to create a date function in InfoPath using JScript I need