SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: fake DOM

  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Location
    BOSTON
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    fake DOM

    alright..
    i don't know if what i am asking can be done, but it is an interesting situation that may require a work around..
    so...
    i am passing the result of an xml document query into a DHTML editor, and the editor does NOT display the entire document, but rather only the content within the body tags which is normal procedure for the component
    now the problem is i want to get a hold of the title in the head, and the DHTML component even supplies a function for get title, AND a function that returns the head of the xml doc, but! the problem is that the title is under a meta tag with that looks like this

    <meta name="DC.title" content="THE TITLE I WANT"/>
    follow:
    tbContentElement.DocuemntHTML returns the head of the xml document, but to parse it i need to load it into a DOM or some other parseable node list...
    i know i can do this through massive string manipulation, but i would rather not, and
    if anybody has more experience using document.createDocumentFragment(); or something similiar please help
    i'll be chillin right here working on this bad larry!
    any input is appreciated!
    thanks

    EDIT: basicly i need to know a way to load up a dom fragment within a javascript window
    thanks!
    Last edited by PCMOVER; Apr 3, 2002 at 13:42.
    PEACE

  2. #2
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Since you know the code surrounding the bit you DO want, just use a regular expression to retrieve the value you want!

    Here's some code that will do the job:
    Code:
    <SCRIPT LANGUAGE="JavaScript">
    var teststring = '<blah><meta name="DC.title" content="THE TITLE I WANT"/></blah>';
    var regpatt = /<meta name="DC.title" content="([^"]*)"\/>/;
    
    var title = regpatt.exec(teststring)[1]
    
    alert(title);
    </SCRIPT>
    Read up here:
    http://www.webreference.com/js/column5/index.html


    M@rco

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Location
    BOSTON
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Right on

    Thanks for the link M@rco,
    I wish more people knew of tutorials where all the sample material was simpsons based!
    I have done some perl back in the day, but let me see if i got this correct from the context of your javascript regexp link...
    load the test string,
    load the regpatt string with search delimited by /
    it matches the entire search criteria, and then when i gets to the " after content, the class takes everything until it gets to the next ",
    title is set to the execution of the search after it occurs once...
    if this is right on, then good for me, if it isn't then DOH!

    thanks a lot!
    PEACE

  4. #4
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Woo-hoo (as exclaimed by Homer)! You're right!

    The code I provided should do exactly what you need - all you need to to is change it so that it runs the match against your header string (which in your case is full of XML).

    The pattern will match only the entire element you specified, and return the part in brackets as a submatch, which is then present in the second position of the array (the first, index 0, is the entire match).

    I have concatenated the line so that it gets the value of this array index directly, rather than as two separate lines. Thus the variable "title" contains your title!

    You will probably need to add error handling for when that element is present (unless you know it's ALWAYS going to be present).


    M@rco


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •