473,785 Members | 2,476 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Distinguish between empty string and no children, in XPath 2?


Let's say we have a schema (maybe expressed in XML Schema, but not
necessarily so), that allows this instance document:

<top>
<txt>This is text</txt>
<books>
<book>Tarzan</book>
<book>Harry Potter</book>
</books>
</top>

The text /top/txt may be empty, and the element /top/books may have no
children, so this instance document is also allowed:

<top>
<txt/>
<books/>
</top>

I now want to write an XPath expression that selects all nodes that do
not have children in the schema. It would always select /top/txt and
it would never select /top/books, even in the second example above.

With XPath 1.0, this is not possible, since schema information is not
used there. But can it be done in XPath 2.0? I find the standard
document a bit forbidding, although I'm fairly well acquainted with
the 1.0 document.

We would like to add such capability to the XPath 1.0 implementation
in our application (which does have access to the schema), and if
XPath 2.0 offers a way to express it, it seems best not to reinvent
anything, hence this question.

Sep 5 '08 #1
3 3091
Arndt Jonasson wrote:
Let's say we have a schema (maybe expressed in XML Schema, but not
necessarily so), that allows this instance document:

<top>
<txt>This is text</txt>
<books>
<book>Tarzan</book>
<book>Harry Potter</book>
</books>
</top>

The text /top/txt may be empty, and the element /top/books may have no
children, so this instance document is also allowed:

<top>
<txt/>
<books/>
</top>

I now want to write an XPath expression that selects all nodes that do
not have children in the schema. It would always select /top/txt and
it would never select /top/books, even in the second example above.

With XPath 1.0, this is not possible, since schema information is not
used there. But can it be done in XPath 2.0? I find the standard
document a bit forbidding, although I'm fairly well acquainted with
the 1.0 document.
Even in the XSLT 2.0 data model the txt element has a child node, it is
a text child node. So your description of saying does not have "children
in the schema" is not very precise. Are you looking for elements which
have a simple type in the meaning of the W3C schema language, meaning
they have no child _elements_ and no attributes? I am not sure whether
schema aware XSLT 2.0 allows you do detect elements which have a simple
type respectively do distinguish in your stylesheet between elements
having a simple type and those having a complex type. As far as I know
all you can do is match an element based on its type and validate input
or output elements based on a schema.

You might want to ask on the XSL mailing list
http://www.mulberrytech.com/xsl/xsl-list/, spec writers and implementors
like Michael Kay are regulars there so you should get a more qualified
answer there than here.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 5 '08 #2
On Sep 5, 2:00 pm, Martin Honnen <mahotr...@yaho o.dewrote:
Even in the XSLT 2.0 data model the txt element has a child node, it is
a text child node. So your description of saying does not have "children
in the schema" is not very precise. Are you looking for elements which
have a simple type in the meaning of the W3C schema language, meaning
they have no child _elements_ and no attributes?
Yes, I mistakenly left out the word "element".
You might want to ask on the XSL mailing listhttp://www.mulberrytec h.com/xsl/xsl-list/, spec writers and implementors
like Michael Kay are regulars there so you should get a more qualified
answer there than here.
Thanks, I'll try there.
Sep 5 '08 #3

"Arndt Jonasson" <ar************ @gmail.comwrote in message
news:3d******** *************** ***********@z66 g2000hsc.google groups.com...
>
Let's say we have a schema (maybe expressed in XML Schema, but not
necessarily so), that allows this instance document:

<top>
<txt>This is text</txt>
<books>
<book>Tarzan</book>
<book>Harry Potter</book>
</books>
</top>

The text /top/txt may be empty, and the element /top/books may have no
children, so this instance document is also allowed:

<top>
<txt/>
<books/>
</top>

I now want to write an XPath expression that selects all nodes that do
not have children in the schema. It would always select /top/txt and
it would never select /top/books, even in the second example above.
This is possible in XPath 2.0 if the schema has separate types for all cases
of element that must not have children-elements.

Then one can use the so called ElementTest, which is defined in the
following way:

ElementTest ::= "element" "(" (ElementNameOrW ildcard (","
TypeName "?"?)?)? ")"
One of the possible XPath 2.0 expressions will be something like the
following:

//element(*,Type1 ) | //element(*,Type2 ) | ... |
//element(*,TypeN )
where Type1, Type2, ..., typeN are all the schema types that define
elements that cannot have children-elements.

Probably substitution groups can be used so that all types above can be
derived from a single abstract type, let's say "ChildlessEleme nt".

Then the expression would be simply:

//element(*,Child lessElement)
Of course, to be able to evaluate such XPath 2.0 expressions one must have a
full-blown XPath 2.0 implementation (either a Schema-Aware XSLT 2.0
processor, or an XQuery processor)

For more information see the XPath 2.0 spec:

http://www.w3.org/TR/xpath20/#doc-xpath-ElementTest

http://www.w3.org/TR/xpath20/#id-element-test
Cheers,
Dimitre Novatchev



Sep 7 '08 #4

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

Similar topics

6
3512
by: Chris Connett | last post by:
I have an interesting problem with eval(). ---Background Info--- The program I'm working on launches a separate process with a popen to do some highly specialized processing of input, then this process leaves resultant data structured in files, in python syntax, at a known absolute path, which is then read in, eval()'ed, and processed further. It works fine when there are no errors in processing by this external program, but when there...
10
23397
by: David Graham | last post by:
Hi I have been busy going through the last weeks postings in an attempt to absorb javascript syntax (I guess it's not possible to just absorb this stuff in a passive way - I'm getting way out of my depth with most of the posts, I will buy a good book and take some online tutorials) Anyway, I think I almost understand one of Mr Nielsen's posts on form validation. It all centers around whether I am interpreting an empty string correctly -...
3
4688
by: krofak | last post by:
Today, I noticed different empty string behaviour then I am used to. Before, empty string was treated as null, so statement vcResult := 'something' || '' would result in vcResult = ''. Today, result of this statement was vcResult = 'something'.
11
4608
by: Dan Bass | last post by:
which one do you use and why? MyString == null || MyString == "" vs MyString == null || MyString.Length == 0
4
2350
by: web1110 | last post by:
I have an array of of 5 string elements. I put values in 3 of them. Yet when I loop over them, I do not catch the empty string. The code output below does not include "Empty" stringx=new String; x="111"; x="222"; x="333";
21
5760
by: M D | last post by:
You know how you assume you know until you find out you don't know. Well, I typed into a function definition "..., new String("")). I know what I want. Everyone reading this knows what I want. However, the 1.0 compiler has no idea what I want. Can anyone share with me the syntax that will actually communicate the concept to the compiler, please?
3
1419
by: scorpion53061 | last post by:
I have little hope of resolving this as I have had to contact outside help. But I thought I would post it here to see if anyone could add an idea or solution. 1. I have a form in a Class Control library along with 6 other namespaces. My root functions are in this form and all the other namespaces revolve around this form. I add the project as a dll to another windows project and call its functions there. Option Strict is
26
3812
by: Neville Lang | last post by:
Hi all, I am having a memory blank at the moment. I have been writing in C# for a number of years and now need to do something in VB.NET, so forgive me such a primitive question. In C#, I test whether a string has a value or not by the following syntax: if (thisString.Trim() == "") {
7
63126
by: tomlebold | last post by:
Are the following two validation the same: 1) IsNull(Me.ColumnName) and Me.ColumnName = "" 2) Me.ColumnName """ It would seem to be better to use: Me.ColumnName """
2
14199
by: Jay | last post by:
I have a SQL Server table with nvarchar type column which has not null constraint. I am inserting empty string ("") from Java to the table column. When I export this table into .csv file using bcp tool, empty string gets written as NUL character. Is there any way I can bcp out empty string as empty string itself instead of NUL to the file? The bcp command I used to export table into csv file is bcp "SELECT...
0
9481
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10341
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10155
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9954
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8979
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5383
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.