|
|
![]() |
|
|
Top | #1 |
|
OSNN Addict
Joined: March 2003
Posts: 99
Reputation: 0
Power: 113 |
-XML File- <numbers> <tim>555-1234</tim> </numbers> -HTML File- <html> <head> <script>document.write(XML.numbers.tim)</script> </head> </html> I know that's not all quite correct, but is there a way I could do something like that in such an easy way? Thanks. |
|
|
|
|
|
Top | #2 |
|
OSNN Veteran Addict
Joined: March 2002
Location: United Kingdom
Posts: 7,805
Reputation: 1490
Power: 217 |
first you would need to write an XML Document Type to define all the elements, then you have to write an XML parser
|
|
|
|
|
|
Top | #3 |
|
OSNN Addict
Joined: March 2003
Posts: 99
Reputation: 0
Power: 113 |
Hmm, I have no clue what that means. Could you or someone else explain further?
|
|
|
|
|
|
Top | #4 |
|
OSNN Veteran Addict
Joined: March 2002
Location: United Kingdom
Posts: 7,805
Reputation: 1490
Power: 217 |
well basically you have to have a Document Type Definition (DTD) which defines the tags and their heirarchy, then you would have to create the XML document with the link to the DTD in the header
To convert the XML to HTML you either have to use an XML parser which takes the XML document and somehow fits the data into HTML or an XSLT which is a special kind of style sheet for defining how certain elements should be rendered I'll see if I can knock together a quick XML DTD which you could use |
|
|
|
|
|
Top | #5 |
|
OSNN Veteran Addict
Joined: March 2002
Location: United Kingdom
Posts: 7,805
Reputation: 1490
Power: 217 |
The XML Document Type Definition (phonebook.dtd)
Code:
<?xml version="1.0" encoding="UTF-8"?> <!ELEMENT phonebook (name+)> <!ELEMENT name (#PCDATA)> <!ATTLIST name number CDATA #REQUIRED > Code:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE phonebook SYSTEM "phonebook.dtd"> <phonebook> <name number="5551234">Tim Jones</name> <name number="5556980">Jem Wilde</name> <name number="5559730">Judy Wilson</name> </phonebook> |
|
|
|
|
|
Top | #6 |
|
OSNN Addict
Joined: March 2003
Posts: 99
Reputation: 0
Power: 113 |
An what should the HTML/JavaScript look like? In other words, how to I get this information from the XML and write it to the web page.
|
|
|
|
|
|
Top | #7 |
|
OSNN Junior Addict
Joined: May 2004
Posts: 8
Reputation: 0
Power: 99 |
I've had the same issue, and here's how I fixed it. First of all my page isn't in HTML, but in XML, I've rewritten a few templates in XSL that transform my XML into HTML, nothing tricky there.
In my transformation, I wanted to get data from an XML file other than the one being transformed, and there's an easy way to do it, without using javascript at all. If you use this syntax: <xsl:value-of select="document('myfile.xml')/tag01/tag02/tag03" /> you'll get the value you're looking for. if you wanna know more about the syntax, refer to XPath tutorials, you'll see what's possible when it comes to fetching some specific tags into an external file. Let me know if this helps. I know you were looking for HTML rather than XML, but playing with XSLT is not that complicated, and will considerably simplify the development of a page. |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| simple question | ProtocolX | Web Design & Coding | 3 | December 16th, 2003 1:05am |
| Just a simple question... | PlagueWielder | Windows Desktop Systems | 15 | October 6th, 2003 8:10pm |
| Plz help.. simple question | HellyHans | Windows Desktop Systems | 3 | June 6th, 2003 7:45pm |
| Simple question..... | robin.munro | Windows Desktop Systems | 3 | July 3rd, 2002 12:24am |
| simple question | jams | Windows Desktop Systems | 8 | April 29th, 2002 3:17pm |