xml, case; required lower?

M

mk834tt

xml rookie. Do custom tags in an xml file need to be lower case?
(answering with an absolute no xlates into my problem. You can skip
the rest.)
Thanks.

I am trying to collect element text from an xml file. I have two.
They are identical except in tag case; <BOOKS> verses <books>. Here
are the xml "functions" I use in this exercise. XML files with upper
case tags to not parse. Is there anything about these functions below
that would require lower case tags? In fact, DO xml tags require
lower case. I understood they were case sensitive only. Here are the
funtions (ff2):

===================================================
xmldoc = document.implementation.createDocument("","",null);

xmldoc.async = false;

xmldoc.load("cdlc.xml");
//xmldoc.load("cduc.xml");
path = "/catalog/cd/title";
//path = "/CATALOG/CD/TITLE";

title_nodes = document.evaluate(
path, xmldoc, null, XPathResult.ANY_TYPE, null);
===================================================

The path is changed to "/CATALOG/CD/TITLE" for the upper case
xml file. I have tried this on two other xml files. Results are
indintical.
Upper - no data, lower - works fine.

Sample xml file:

<?xml version="1.0" encoding="ISO-8859-1"?>

<catalog>

<cd>
<title>lite</title>
<author>sdfsf</author>
</cd>
<cd>
<title>medium</title>
<author>qewrwt</author>
</cd>
<cd>
<title>heavy</title>
<author>lkjlkj</author>
</cd>

</catalog>
 
J

Janwillem Borleffs

xml rookie. Do custom tags in an xml file need to be lower case?
(answering with an absolute no xlates into my problem. You can skip
the rest.)
Thanks.

No.


JW
 
J

Janwillem Borleffs

Janwillem said:

Having said that, you need to be aware that XML is case-sensitive. When a
DTD or schema describes a "BOOK" element, you can't just use "book" instead.


JW
 
M

mk834tt

Having said that, you need to be aware that XML is case-sensitive. When a
DTD or schema describes a "BOOK" element, you can't just use "book" instead.

JW

Ah, so. Maybe that's the problem. I thought I could get away without
using
a dtd or xds. Perhaps the methods make some assumptions here.

Thank you.
 
M

Martin Honnen

xml rookie. Do custom tags in an xml file need to be lower case?

No, but XML and XPath is case-sensitive meaning if your XML document
contains an element named 'book' then your XPath needs to have 'book'
too to select the element and if your XML document has an element named
'BOOK' then your XPath needs 'BOOK' too.
 
D

Dag Sunde

Ah, so. Maybe that's the problem. I thought I could get away without
using
a dtd or xds. Perhaps the methods make some assumptions here.

Your problem is that two xml-files that is identical *except* for the
case is considered as two completely different files from the parsers
point of view.

The 4 paths below refer to 4 completely different elements in an xml file:
path = "/catalog";
path = "/CATALOG";
path = "/Catalog";
path = "/cataloG";

You can't hardcode XPath strings in your code and expect it to work
on files with different case in their tags.

1. Make a desition on what case you will support.
2. Write an xsd/dtd that specifies that case and structure.
3. make your application validate the xml-file against your xsd/dtd
before using the file. If validation fails, log it or tell the user.
4. If validation succeeds, use your XPaths and start working with the file.
 
T

Thomas 'PointedEars' Lahn

Dag said:
Your problem is that two xml-files that is identical *except* for the
case is considered as two completely different files from the parsers
point of view.

The 4 paths below refer to 4 completely different elements in an xml file:
path = "/catalog";
path = "/CATALOG";
path = "/Catalog";
path = "/cataloG";

You can't hardcode XPath strings in your code and expect it to work
on files with different case in their tags.

1. Make a desition on what case you will support.
2. Write an xsd/dtd that specifies that case and structure.
3. make your application validate the xml-file against your xsd/dtd
before using the file. If validation fails, log it or tell the user.
4. If validation succeeds, use your XPaths and start working with the file.

Alternatives include using XSLT and other approaches for markup
transformation before applying XPath on the result.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top