New to XML

M

MS

I am brand new to XML and doing some practice stuff. I am missing a
simple concept and I am hoping someone can shed some light.

I am learning how to tie in HTML and XML but everything I have done so
far, the XML file has resided in the same directory on my local pc.

Can you retrieve or view XML files via the web from another location
and display them in an HTML document using noting but HTML? If so, how
do you query this data?
 
P

Paulo Pinto

If you're using a browser that's easy.
Just use CSS for formating. the presentation.

But what do you mean by 'querying the data'?
Where do you want to do that?
 
P

Peter Flynn

MS said:
I am brand new to XML and doing some practice stuff. I am missing a
simple concept and I am hoping someone can shed some light.

I am learning how to tie in HTML and XML but everything I have done so
far, the XML file has resided in the same directory on my local pc.

Can you retrieve or view XML files via the web from another location

Yes, just upload them to your web server. Make sure your server operator
or webmaster has set the mime.types file to serve .xml files correctly
(see the FAQ for details: http://www.ucc.ie/xml)

You'll need to write a CSS stylesheet to go with them, otherwise they
will be displayed unformatted. Browsers have no built-in formatting rules
for XML like they do for HTML, so a stylesheet is essential if you want
the document formatted.
and display them in an HTML document using nothing but HTML?

To do this you have three choices:

a) use XML files with XSLT stylesheets on with server that does XML to HTML
conversion, such as AxKit, Cocoon, or PropelX.

b) use XML files with XSLT stylesheets that get downloaded by the user's
browser and converted in the browser (currently restricted to recent
browsers only: MSIE5/6, Mozilla Firefox, Opera [Safari and Konqueror
to follow soon, I believe]) so users of older browsers will be SOOL.

c) use XHTML, but serve the file as MIME type text/hmtl. This is enough
to fool most browsers, but you are imposing quite severe restrictions
on yourself in terms of data identity and document management by using
XHTML (unless you actually use some other form of XML and convert to
XHTML statically before serving).
If so, how do you query this data?

That's a different thing altogether. If you just want to let users search
it, you'll need an XML search engine (there's one with Cocoon called Lucene)
but if you want them to be able to construct programmatic queries, you can
either program an interface to let them do it (which means scripting the
response-handler) or you can provide a selection of pre-programmed queries
(eg in XSLT) to which they can provide data values. XQuery provides a
syntax, but you'll need to write the surrounding code.

///Peter
 
M

MS

For my query question, if I wanted to allow a user to query last names
for 'Jefferson', is there a way to do this in XML?

<?xml version='1.0'?>
<?xml-stylesheet type="text/xsl" href="Names.xsl"?>
<!DOCTYPE ListOfNames SYSTEM "Names.dtd">

<ListOfNames lang="English">
<Name>
<FirstName>William</FirstName>
<LastName>Thomas</LastName>
</Name>
<Name>
<FirstName>Thomas</FirstName>
<LastName>Jefferson</LastName>
</Name>
<Name>
<FirstName>Mike</FirstName>
<LastName>Jones</LastName>
</Name>
</ListOfNames>
 
?

=?ISO-8859-1?Q?J=FCrgen_Kahrs?=

MS said:
For my query question, if I wanted to allow a user to query last names
for 'Jefferson', is there a way to do this in XML?

You said you use a DOM-approach.
Once your data base grows too large, the DOM
might become a problem. But a SAX-approach is
quite adequate for simple queries like the one
you mention. Here is a SAX-based solution i
XMLgawk:

BEGIN { XMLMODE=1 }

XMLCHARDATA { data = $0 }
XMLENDELEM == "FirstName" { first = data }
XMLENDELEM == "LastName" { last = data }
XMLENDELEM == "Name" {
if (last == "Jefferson")
print first, last
}


The output of this script is:

Thomas Jefferson
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top