|
|
I thought this would be simple. I have a dictionary of sorts; I want to display just the terms in the XML doc. Then when I click on the term I'd like to see it's definition. The problem is how to pass the var to the xslt. ...make sense?
|
|
|
|
|
You can accomplish this, if you're doing this through a browser, with a little bit of processing either in the browser or on the server. In either case, the processing you do is the same. The short story is that you use an XPath expression to extract the value of the node(s) you want to display. Here are the details:
I'm going to give you details from part of an example from my soon to be available book not for name recognition, but simply because it is a good example that demonstrates the technique.
Assume that you have a site that publishes book reviews - the details of each book (title, author, etc) along with book reviews reside an an XML file that has a relative simple structure. When users hit the site, they receive a page that lists all books and provides a link to the review. The page, in one part of the sample, actually not an HTML page but is an XML file that's transformed on the client using XSL (so the URL users see in the address bar ends in a file name having an XML extension). This, so far, is the first bit of processing you need to do - transform the XML document (in your case the document that contains information about the directory) into a presentable format.
The next bit of processing occurs when the user clicks on a record (or book review in this example) to get the details. I made this part of the process easier for myself back in the previous step: I generated links that provide the information I need in this step to extract the information the user wants. In the sample, I generate links that point to an HTML page along with some information on the querystring, to the link I generate looks something like this:
<a href="displayReview.htm?Book Title">Book Title</a>
So that when the user clicks the link, displayReview.htm can extract the review from the XML file. displayReview.htm contains a little bit of JavaScript that does the following:
- Extracts the text passed in on the querystring.
- Creates an instance of the XML DOM.
- Loads the book reviews document into the DOM.
- Creates another instance of the DOM.
- Loads an XSL file into the second DOM.
- Builds an XPath expression that includes the book's title.
- Uses the selectSingleNode method to execute the XPath query.
- Uses the transformNode method to transform the resulting node into some presentable format for the end user.
- Stuffs the result into the content of the HTML document.
It looks rather involved here, but it is straight-forward once you see it in action. My book actually implements the sample in two ways: XML, XSL and HTML with JavaScript (this implementaiton), and ASP where all the processing is done on the server and clients receive static HTML.
Good luck!
Erik Westermann
Author, Learn XML In A Weekend (Fall 2002)
|
|
|
|
|
I'm trying to build an XML file in Java to persist data for an application between sessions. I'd like to build a structure like this
<Files>
<Entry>somefile.txt</Entry>
<Entry>otherfile.txt</Entry>
</Files>
How can I do this? I've figured out how to generate it with attributes:
<Files>
<Entry entry=somefile.txt/>
<Entry entry=otherfile.txt/>
</Files>
But that's not the way I need to do it. Can anyone make a suggestion?
Thanks.
|
|
|
|
|
java.sun.com
try the boards there...
Ryan Baillargeon
Software Specialist
Fuel Cell Technologies Inc.
|
|
|
|
|
Hello guys,
I am designing an XML database and need some pointers.
The database i am designing will be used to store configuration information - it will be similar to the type of database that a firewall might have - different rules with different settings.
It will not be used on any special web application - it will be used as an internal configuration database for a local C++ application.
I wanted to know if:
1) There are any XML/XML schema authoring tools which will assist me in creating the database and its relationships.
2) There are any XML schemas that exist which are similar to the model I am looking for. I could use these for reference since i am pretty new to XML.
3) I need to know which is the best way to extract the XML from my XML file(or files). The database could potentially be quite large, and i do not want to load the whole thing in memory before using it. I also do not want to reparse the entire document each time i need to make a query on it. I have heard of XPATH, scripting, DOM and SAX. I might even use a combination of them. Does anyone know which might be the best suited? Also, has anyone ever heard of XML query language?
I have available quite a variaty of books (most from Wrox press). If anyone has good suggestions for more books I could buy, please let me know.
Thanks a lot for the help!
Jeremy.
Jeremy Pullicino
Professional C++ Developer
Done any hacking lately?
|
|
|
|
|
Jeremy Pullicino wrote:
Also, has anyone ever heard of XML query language?
This[^] might be of some help to you.
You can find a few references to XQuery implementations in this article[^].
HTH (to some extent)
Zdenek
"It's never too late to have a happy childhood." [Tom Robbins]
|
|
|
|
|
Don't about many Schema authoring tools. I use XML Spy for XML, XSD etc.
You may want to consider using XSLT for extracting data. If you design your code to apply an XSL to extract data from the XML then you have the flexibility of changing the XSL or creating additional XSLs for extracting different parts of the XML database wityhout having to change your code. Just an idea....
|
|
|
|
|
Thanks about the XML Spy tip, I will make sure to download a copy of it today.
I am worried about XSL for extracting data since performance is an issue for me (this database is read many times every second, from multiple threads, 24hrs a day).
I was thinking of dynamically creating a schema with the fields I will want, and then extracting the data into that schema - however, I am stil learning about XML, so this might be too advanced for me right now.
Thanks for the tips though
XML is truly great.
Jeremy Pullicino
Professional C++ Developer
Done any hacking lately?
|
|
|
|
|
The fastest way to extract data from an XML document is to use SAX (Simple API for XML)[^]. All major vendors provide an implemetaion, but it is not a standardized API (a standards body does not control the API) - it is a de fecto standard.
SAX uses a streaming model where the XML parser notifies your applicaiton whenever it reads a part of the document and provides the details to you in plain text. There's a good article, part of which describes the SAX programming model at the 'other' site[^].
SAX scales well, but if you're still concerned about performance then you can just read the XML directly usinng file I/O and parse it yourself - that's as efficient as it gets but is difficult to maintain.
Jeremy Pullicino wrote:
dynamically creating a schema with the fields I will want
No need to do this - see my other post about getting data from an XML document. That post uses the DOM, which may end up being too slow for your needs. Again, you can use SAX bu then extracting the relevant data is left an an excercise for you or you can od the do-it-yourself route and again have to deal with that issue but with the benefit of muh better performance.
Erik Westermann
Author, Learn XML In A Weekend (Fall 2002)
|
|
|
|
|
Jeremy Pullicino wrote:
I am designing an XML database and need some pointers.
Just quickly have a look at TeXtML[^] for an actual XML Database. Also they maky have whitepapers and links to resources on XML databases.
Jeremy Pullicino wrote:
Also, has anyone ever heard of XML query language?
Yes, read about it at W3C and Google has plenty of links. FYI XSL is used for transforming XML while XQuery is for querying. Though in reality they are very similar and people chop and change between them.
Paul WatsonBlueGrassGroup.com Cape Town, South Africa
|
|
|
|
|
Thanks for the tips especially the links.
The xml database looks good - their site gave me many tips on how XML could be used in databases.
Jeremuy.
Jeremy Pullicino
Professional C++ Developer
Done any hacking lately?
|
|
|
|
|
Paul Watson wrote:
Anybody have any clue as to how to pause an animation in SVG?
Figured it out eventually, call the following method in your SVG doc to pause document.rootElement.pauseAnimations(); and to unpause/resume document.rootElement.unpauseAnimations(); .
Bloody hell if I may say so. All the other leads I followed were complex masterpieces of JavaScript, and that works with just one line. Doh!
|
|
|
|
|
Is there any FREE XML editors like XMetaL 3.0??
XMetaL 3.0 is too expensive for me!
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
lol
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
Why LOL?
And why is my message gone!?
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
does anyone know how to tell the parser to ignore special characters in element attributes?
say i have an element:
<br />
<setting name="CommandLine" value="notepad.exe "C:\Documents and Settings\moralja\My Documents\text\text.txt""></setting><br />
this will not parse correctly because of the quote marks inside the value attribute.
just encoding the quotes with " works, but i am going to have possibly thousands of entries, i would rather have some way, like the CDATA thing, to tell the parser to ignore the data altogether
any ideas?
-John
|
|
|
|
|
John Morales wrote:
just encoding the quotes with " works, but i am going to have possibly thousands of entries, i would rather have some way, like the CDATA thing, to tell the parser to ignore the data altogether
I may be wrong but the answer is no. If you think about it having quotes like that in the attribute value breaks the whole parsing of the element.
I would recommend you move that attribute to an element e.g.:
<setting name="CommandLine">notepad.exe "C:\Documents and Settings\moralja\My Documents\text\text.txt"</setting>
It actually makes more sense that way too.
And if you think that will be a pain with thousands of entries, you could always write a simple XSL file which does it for you in a couple of minutes
regards,
Paul Watson
Bluegrass
Cape Town, South Africa
Simon Walton wrote:
"You come across a lot of people who call themselves realists, when they are actually pessimists attempting to look intelligent."
|
|
|
|
|
Hello;
I have trouble with XML. I have XML document like following;
root
A id="97033536"
B id="09417"
C id="09418"
D
E M18 /E
/D
/C
/B
B id="09417"
C id="09419"
D
E M18 /E
/D
/C
/B
/A
/root
I want to get data in 2 rows like;
97033536 09417 09418 M18
97033536 09417 09419 M18
How can i get this result in Visual Basic with DOM?
Thanks...
Ahmet Orkun GEDiK
|
|
|
|
|
One way is to create an XSL and then transform the XML. This can be done by creating two DOM Documents. Load the XML in one and the XSL in one. call TranformNode for the XML by passing the XSL. The XSL could look something like:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes">
<xsl:template match="/">
<xsl:apply-templates select="/A">
<xsl:template match="A">
<xsl:for-each select="B">
<xsl:value-of select="/A/@id">
<xsl:text>
<xsl:value-of select="/A/@id">
<xsl:apply-templates select="C">
<xsl:template match="C">
<xsl:text>
<xsl:value-of select="@id">
<xsl:apply-templates select="D">
<xsl:template match="D">
<xsl:text>
<xsl:value-of select="E">
I like this approoach because if you wish to chnage the format of your data later on all you have to do is change the XSL and your code remains the same.
|
|
|
|
|
Hello;
I have trouble with XML. I have XML document like following;
<root>
<c id="09418">
<d>
<e>M18
<c id="09419">
<d>
<e>M18
I want to get data in 2 rows like;
97033536 09417 09418 M18
97033536 09417 09419 M18
How can i get this result in Visual Basic with DOM?
Thanks...
Ahmet Orkun GEDiK
|
|
|
|
|
Hey Guys,
I am using ASP to load some data from a xml file via xsl. Now i need to sort this data, i know i could use the xsl:sort element but i need a dynamic one, which the user can change. So the user will have the possibilty to sort the data in different ways. I already tried to pass a param to xsl and put it to <xsl:sort> but it didnt worked.
Isnt it possible to pass a sort statement in selectnodes ?
Is there any such function ?
Any suggestions ??
thanks
Sonu
da sonu
|
|
|
|
|
If you are using DOM then try the following. Based on the user's selections create an XSL with the appropriate sort and then apply it to your XML using the DOMDoc object.
|
|
|
|
|
I am using DOM, but i am not very familiar with that. Do you have any example code which might help me ?
da sonu
|
|
|
|
|
Hi,
try to put this code:
<xsl:sort order="ascending" data-type="text" select="//records/*[name() = $OrderField]"/>
Where the parameter $OrderField contains the name of the field to order.
Pau
|
|
|
|