473,395 Members | 1,675 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,395 software developers and data experts.

upper-casing parts of xpath

Hi there,

I'd like to apply an xpath to both HTML and XHTML documents. First I
create a DOM document with a Java DOM parser, then apply the xpath with
Xalan's XPathAPI class. The problem is that in HTML DOM element names
are all upper-case, whereas in Core DOM (used for the XHTML documents)
element names are lower-case. When I use a lower-case xpath, e.g.

/head[@profile='http://www.example.org/MyProfile']

it won't match with a head element in an HTML document. OTOH, when I use

/HEAD[@profile='http://www.example.org/MyProfile']

it won't match with a head element in an XHTML document.

I cannot make the whole xpath lower-case in case of an XHTML document,
because there may be case-sensitive things in the xpath, like the URL in
the example above.

There may be some Java classes to parse the xpath string and get the
element names to make them upper-case for HTML. Does anyone know of such
things?
--
Johannes Koch
In te domine speravi; non confundar in aeternum.
(Te Deum, 4th cent.)
Jul 20 '05 #1
3 5036
Johannes Koch wrote:
Hi there,

I'd like to apply an xpath to both HTML and XHTML documents. First I
create a DOM document with a Java DOM parser, then apply the xpath with
Xalan's XPathAPI class. The problem is that in HTML DOM element names
are all upper-case, whereas in Core DOM (used for the XHTML documents)
element names are lower-case. When I use a lower-case xpath, e.g.

/head[@profile='http://www.example.org/MyProfile']

it won't match with a head element in an HTML document. OTOH, when I use

/HEAD[@profile='http://www.example.org/MyProfile']

it won't match with a head element in an XHTML document.

I cannot make the whole xpath lower-case in case of an XHTML document,
because there may be case-sensitive things in the xpath, like the URL in
the example above.

There may be some Java classes to parse the xpath string and get the
element names to make them upper-case for HTML. Does anyone know of such
things?


hi,

maybe you have to plug a sax parser that do the job before building the
DOM model ?

another solution is to use Jaxen instead of Xalan's XPathAPI ; instead
of parsing xpath expressions with jaxen.dom.DOMXPath, you can parse them
with a copy of the package jaxen.dom.*, for example koch.dom.* ; the
main class is DocumentNavigator, that you have to extend to write your
own methods, such as getElementName() that should give upper-case names...
easy !

the last solution is to use Jaxen again, and write your own SAXPath
parser ; but i don't know really where to act exactly
--
Cordialement,

///
(. .)
-----ooO--(_)--Ooo-----
| Philippe Poulard |
-----------------------
Jul 20 '05 #2
In article <2q*************@uni-berlin.de>,
Johannes Koch <ko**@w3development.de> wrote:
/head[@profile='http://www.example.org/MyProfile']
/HEAD[@profile='http://www.example.org/MyProfile']


You could (rather tediously) write

/*[local-name()='HEAD' or local-name='head'][@profile='http://www.example.org/MyProfile']

-- Richard
Jul 20 '05 #3
Johannes Koch wrote:
Hi there,

I'd like to apply an xpath to both HTML and XHTML documents. First I
create a DOM document with a Java DOM parser, then apply the xpath with
Xalan's XPathAPI class. The problem is that in HTML DOM element names
are all upper-case, whereas in Core DOM (used for the XHTML documents)
element names are lower-case. When I use a lower-case xpath, e.g.

/head[@profile='http://www.example.org/MyProfile']

it won't match with a head element in an HTML document. OTOH, when I use

/HEAD[@profile='http://www.example.org/MyProfile']

Hi,

You could write a pre-processor XSL program that converts all uppercase
tags to lower-case tags. And then feed the output to your regular
program. Shown below is an example of such a pre-processor (warning :
not extensively tested. use at your own risk) :

<?xml version="1.0"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>

<xsl:template match="*">
<xsl:variable name="elementName"
select="translate(local-name(),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklm nopqrstuvwxyz')"
/>
<xsl:element name="{$elementName}">
<xsl:for-each select="@*">
<xsl:apply-templates select="." />
</xsl:for-each>
<xsl:apply-templates />
</xsl:element>
</xsl:template>

<xsl:template match="@*">
<xsl:variable name="attrName"
select="translate(local-name(),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklm nopqrstuvwxyz')"
/>
<xsl:attribute name="{$attrName}">
<xsl:value-of select="." />
</xsl:attribute>
</xsl:template>

<xsl:template match="text()">
<xsl:value-of select="." />
</xsl:template>

</xsl:stylesheet>

Regards,
Kenneth
Jul 20 '05 #4

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

Similar topics

4
by: programmerforhire | last post by:
Hello all, Is there a way to setup an ms-access table so that when I enter text in the 'datasheet' mode, it will automatically be converted tp upper case. Or must I use a Form for this? rex
17
by: Janice | last post by:
char* line = "abcd"; How to convert the line to upper case and print? Any option for printf to do this? Thanx
6
by: Manish | last post by:
In my application there is need for only upper case chars.. Currently I am making entry to upper case when user leaves focus of the text control. I want to do some modification here...When user...
2
by: Richard Keller | last post by:
How can I only allow user to enter upper case letters into a text box, and if he enters a lower case letter, change it to upper case. in vb6 I would use the keypress event and change the key to...
3
by: Weiping | last post by:
Hi, while upgrade to 8.0 (beta3) we got some problem: we have a database which encoding is UNICODE, when we do queries like: select upper('ÖÐÎÄ'); --select some multibyte character, then...
19
by: Eric Lindsay | last post by:
Should HTML 4.01 Strict markup be done in upper case or in lower case? I understand that HTML allows either upper or lower case. I also notice that XHTML apparently requires lower case. However I...
8
by: csanjith | last post by:
Hi, i have a situaion where i need to convert the characters entered in an text field to upper case using C. The configuration id utf8 environment in which user can enter any character (single ,...
10
by: John Salerno | last post by:
Can someone tell me what's happening here. This is my code: PUNCT_SPACE_SET = set(string.punctuation + string.whitespace) def filter_letters(original): return ''.join(set(original) -...
5
by: bob | last post by:
Now this ought to be a simple matter. But nothing's simple in the Net world, I'm finding. In vb6 you could use "!" to force text to upper case in the format function. I've searched the vb.net...
2
Thekid
by: Thekid | last post by:
I had made a post about making a loop using letters instead of numbers and dshimer gave me this solution: for i in range(65,70): for j in range(65,70): for k in range(65,70): ...
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: 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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.