george Posted March 2, 2007 Share Posted March 2, 2007 Is this legal? <dates> <month>3</month> <day>10</day> <year>2007</year> <month>3</month> <day>11</day> <year>2007</year> <month>3</month> <day>12</day> <year>2007</year> <month>3</month> <day>13</day> <year>2007</year> </dates> I am trying to document a variable range of dates. TIA Link to comment Share on other sites More sharing options...
boen_robot Posted March 2, 2007 Share Posted March 2, 2007 This is above all, well formed. Valid? I guess not, scince it doesn't have any DTD or schema associated with it. Read the corresponding tutorials to see what I mean.P.S. I'm also missing the XML prolog. Link to comment Share on other sites More sharing options...
george Posted March 2, 2007 Author Share Posted March 2, 2007 Thanks Gobby Link to comment Share on other sites More sharing options...
boen_robot Posted March 2, 2007 Share Posted March 2, 2007 You're welcome, but... my (nick)name is not Gobby actually . Gobby is only an application I kind'a advertise in my signature. My nickname is boen_robot, and that's who you should've thanked . Link to comment Share on other sites More sharing options...
george Posted March 2, 2007 Author Share Posted March 2, 2007 Perhaps I can thank you again then, boen_robot. I am attempting to access the data in my XML document. I have no problem with the tags that are not nested. It's my nested dates that are proving illusive. <?xml version="1.0" encoding="ISO-8859-1"?><eventcatalog> <event> <eventname>Jani at Trios</eventname> <instructor>Dale Tove</instructor> <dates> <month>3</month> <day>10</day> <year>2007</year> <month>3</month> <day>11</day> <year>2007</year> <month>3</month> <day>12</day> <year>2007</year> <month>3</month> <day>13</day> <year>2007</year> </dates> </event> <event> <eventname>Montgomery County Fair</eventname> <instructor>Frances Hall</instructor> <dates> <month>3</month> <day>20</day> <year>2007</year> <month>3</month> <day>21</day> <year>2007</year> <month>3</month> <day>22</day> <year>2007</year> <month>3</month> <day>23</day> <year>2007</year> </dates> </event> <event> <eventname>Alexandria Hospital Fitness Celebration</eventname> <instructor>Linda Frasher</instructor> <dates> <month>4</month> <day>10</day> <year>2007</year> <month>4</month> <day>11</day> <year>2007</year> <month>4</month> <day>12</day> <year>2007</year> <month>4</month> <day>13</day> <year>2007</year> </dates> </event></eventcatalog> From what I have learned so far, it seems there are two ways of reading the data. One using the getElementsByTagName("tagname")[0].childNodes[0].nodeValue; and another using the recordset objectBut still none of the examples I could find sowed me how to get data from dates nodes Any examples for nested tags? TIA boen_robot - george Link to comment Share on other sites More sharing options...
boen_robot Posted March 2, 2007 Share Posted March 2, 2007 I don't know about JavaScript. It would be easy with XPath expressions, but I don't know how/if JavaScript can do this.Care to use XSLT instead, or is it not appropriate for whatever you need this data for? Link to comment Share on other sites More sharing options...
george Posted March 2, 2007 Author Share Posted March 2, 2007 I don't know about JavaScript. It would be easy with XPath expressions, but I don't know how/if JavaScript can do this.Care to use XSLT instead, or is it not appropriate for whatever you need this data for?XML DOM Tutorial is where I need to be. Just FYI:I'm using HTML & PHP & AJAX to populate MySQL tables - recording events each with it's own list of dates. Upon update of the data, an XML file is written (or overwritten), which will be accessed by a three month running calander. The calander then displays scheduled events, and on-mouseover will give details about the particular event highlighted on the calander. Inexpensive Javascript solutions already exist for this. But I'll give myself till Monday to do it myself, then if I can't, I'll buy. Link to comment Share on other sites More sharing options...
boen_robot Posted March 2, 2007 Share Posted March 2, 2007 Well, I'm not that good with DOM, but I guess that you can do it by simply searching the object of the object of the... you got the idea. Something like this perhaps: getElementsByTagName("dates")[0].childNodes[0].getElementsByTagName("month")[0].childNodes[0].nodeValue; This would be the equivalent of this XPath expression (If what I think is right): //dates[1]//month[1] By the way, I think this XML structure might serve you better: <event> <eventname>Jani at Trios</eventname> <instructor>Dale Tove</instructor> <dates> <date day="10" month="3" year="2007"/> <date day="11" month="3" year="2007"/> <date day="12" month="3" year="2007"/> </dates> </event> Not to mention it's more readable as well. Link to comment Share on other sites More sharing options...
jesh Posted March 3, 2007 Share Posted March 3, 2007 Maybe something like this would help you understand the XML DOM (as described in the tutorial). boen_robot's got to be one of the best people here to ask when it comes to how to do things with XML. I only use the DOM because it's the only way I know. // get a reference to the main element.var eventcatalog = myXMLdocument.getElementsByTagName("eventcatalog");// get all the events in the event catalogvar events = eventcatalog.getElementsByTagName("event");// get all the dates in the 3rd event elementvar dates = events[2].getElementsByTagName("dates"); I'm looking forward to seeing this as cross-browser compatible: http://www.w3schools.com/e4x/default.asp Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now