Search Results

Search found 2174 results on 87 pages for 'dom'.

Page 6/87 | < Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >

  • PHP XML Strategy: Parsing DOM to fill "Bean"

    - by Mike
    I have a question concerning a good strategy on how to fill a data "bean" with data inside an xml file. The bean might look like this: class Person { var $id; var $forename = ""; var $surname = ""; var $bio = new Biography(); } class Biography { var $url = ""; var $id; } the xml subtree containing the info might look like this: <root> <!-- some more parent elements before node(s) of interest --> <person> <name pre="forename"> Foo </name> <name pre="surname"> Bar </name> <id> 1254 </id> <biography> <url> http://www.someurl.com </url> <id> 5488 </id> </biography> </person> </root> At the moment, I have one approach using DOMDocument. A method iterates over the entries and fills the bean by "remembering" the last node. I think thats not a good approach. What I have in mind is something like preconstructing some xpath expression(s) and then iterate over the subtrees/nodeLists. Return an array containing the beans as defined above eventually. However, it seems not to be possible reusing a subtree /DOMNode as DOMXPath constructor parameter. Has anyone of you encountered such a problem?

    Read the article

  • change image use javascript DOM

    - by user289346
    <html> <head> <script type="text/javascript"> var curimage = "cottage_small.jpg"; var curtext = "View large image"; function changeSrc() { if (curtext == "View large image"||curimage == "cottage_small.jpg") { document.getElementById("boldStuff").innerHTML = "View small image"; curtext="View small image"; document.getElementById("myImage")= "cottage_large.jpg"; curimage = "cottage_large.jpg"; } else { document.getElementById("boldStuff").innerHTML = "View large image"; curtext = "View large image"; document.getElementById("myImage")= "cottage_small.jpg"; curimage = "cottage_small.jpg"; } } </script> </head> <body> <!-- Your page here --> <h1> Pink Knoll Properties</h1> <h2> Single Family Homes</h2> <p> Cottage:<strong>$149,000</strong><br/> 2 bed, 1 bath, 1,189 square feet, 1.11 acres <br/><br/> <a href="#" onclick="changeSrc()"><b id="boldStuff" />View large image</a> </p> <p><img id="myImage" src="cottage_small.jpg" alt="Photo of a cottage" /></p> </body> </html> This is my coding I need to change the image and text the same time when I click it. I use LTS, it shows the line document.getElementById("myImage")= "cottage_large.jpg"; is a wrong number of arquments or invalid property assigment. Dose someone can help? Bianca

    Read the article

  • using document.createDocumentFragment() child dom elements that contain jQuery.data

    - by taber
    I want to use document.createDocumentFragment() to create an optimized collection of HTML elements that contain ".data" coming from jQuery (v 1.4.2), but I'm kind of stuck on how to get the data to surface from the HTML elements. Here's my code: var genres_html = document.createDocumentFragment(); $(xmlData).find('genres').each(function(i, node) { var genre = document.createElement('a'); $(genre).addClass('button') .attr('href', 'javascript:void(0)') .html( $(node).find('genreName:first').text() ) .data('genreData', { id: $(node).find('genreID:first').text() }); genres_html.appendChild( genre.cloneNode(true) ); }); $('#list').html(genres_html); // error: $('#list a:first').data('genreData') is null alert($('#list a:first').data('genreData').id); What am I doing wrong here? I suspect it's probably something with .cloneNode() not carrying over the data when the element is appended to the documentFragment. Sometimes there are tons of rows so I want to keep things pretty optimized, speed-wise. Thanks!

    Read the article

  • Convert HTML DOM into a multidimensional array

    - by dclowd9901
    Where keys are represented by element type and values are represented by #foo and .bar (spaced and ready for explode()). Is it possible, or does something exist for it? I know that this question might incite some wrath, and I'm hoping nobody links to that post about parsing HTML, but I'm hoping it's not impossible. Thanks for the help. Addendum: Ideally, PHP would be used, since it's the only scripting language I know.

    Read the article

  • DOM + need to remove element from XML bt VB script

    - by yael
    I have the following VB script , I want to remove the "NET ID" element from name list but after running the VB script the "NET ID" element still exist in the XML doc? Something wrong in the VB? Yael Set objXMLDoc = CreateObject("Microsoft.XMLDOM") objXMLDoc.async = False objXMLDoc.load("\dir\d.xml") Set objRoot = objXMLDoc.documentElement Set objExNode = objRoot.removeChild(objRoot.childNodes.item(0)) objRoot.appendChild(objExNode) the XML file:

    Read the article

  • Odd DOM Problem with Firefox

    - by Bob
    Hello. I'm experiencing an odd problem when trying to navigate through a table's rows and cells in a while loop using javascript. I'm using Firefox 3.5.7 on Win7 with Firebug enabled. I have this markup: <table> <tbody> <tr id='firstRow'><td>a</td><td>b</td><td>c</td></tr> <tr><td>a</td><td>b</td><td>c</td></tr> <tr><td>a</td><td>b</td><td>c</td></tr> </tbody> </table> And this javascript: var row = document.getElementById('firstRow'); console.log(row); // Row call 1 while (row) { console.log(row); // Row call 2 row = row.nextSibling; } The problem I'm having is that on the line commented "Row call 1", Firebug is outputting <tr id='firstRow'> as expected. However, in the while loop, Firebug is giving me <tr id='firstRow'> <TextNode textContent="\n"> It is giving me different output for the exact same row, even immediately after the while loop begins executing and nothing else touched the row. For subsequent rows, it of course does not have id='firstRow' as an attribute. The bigger problem this is giving me is that if I'm in the while loop, and I want to access a particular cell of the current row using row.cells[0], Firebug will give me an error that row.cells is undefined. I want to know if someone could shed some light on this situation I am experiencing.

    Read the article

  • highlight the text of the DOM range element,

    - by ganapati
    I am able to highlight the text on the HTML page(rendered through gtkmozembed), which is selected, like below. var range, sel; if (window.getSelection) { sel = window.getSelection(); if (sel.getRangeAt) { range = sel.getRangeAt(0); } document.designMode = "on"; if (range) { sel.removeAllRanges(); sel.addRange(range); } document.execCommand("HiliteColor", false, colour); document.designMode = "off"; } Well,it works very fine.Now i am trying to store the information(startNode, startOffset,endNode, endOffset) about the highlighted text, and next time when i open the same page,highlight the same text. I am able to successfully store the info and retrieve them when the same page opens. And i am trying to highlight the text using following code. var range = document.createRange(); range.setStart(startNode, startOffset); range.setEnd(endNode, endOffset); document.designMode = "on"; range.execCommand("HiliteColor", false, colour); document.designMode = "off"; But it is not working as i am expecting. Can anyone help me to achieve the required? Thanks...

    Read the article

  • W3C dom api in Java, get child elements by name

    - by Benju
    I just realized that the method Element.getElementsByTagName("someTagName") returns a nodelist of all elements in the document that have a given tagname. What if I just want to get all child elements by tag name? For example... <person> <name>Bob</name> <car> <name>Toyota Corolla</name> </car> </person>

    Read the article

  • Javascript DOM encoded html code problem

    - by Kubi
    var accordion = document.createTextNode(tp.getAccordionContent()); var el = document.createElement("div"); el.appendChild(accordion); document.getElementById("gp").appendChild(el); tp.getAccordion() function returns me a string like < div .... and it is being decoded. All I want is to get it encoded and implement the div which has an id = gp with that data. any help and advises would be greatly appreciated.

    Read the article

  • highlight the text of the DOM range element,

    - by ganapati hegde
    I select some text on the html page(opened in firefox) using mouse,and using javascript functions, i create/get the rangeobject corresponding to the selected text. userSelection =window.getSelection(); var rangeObject = getRangeObject(userSelection); Now i want to highlight all the text which comes under the rangeobject.I am doing it like this, var span = document.createElement("span"); rangeObject.surroundContents(span); span.style.backgroundColor = "yellow"; Well,this works fine, only when the rangeobject(startpoint and endpoint) lies in the same textnode,then it highlights the corresponding text.Ex <p>In this case,the text selected will be highlighted properly, because the selected text lies under a single textnode</p> But if the rangeobject covers more than one textnode, then it is not working properlay, It highlights only the texts which lie in the first textnode,Ex <p><h3>In this case</h3>, only the text inside the header(h3) will be highlighted, not any text outside the header</p> Any idea how can i make, all the texts which comes under rangeobject,highlighted,independent of whether range lies in a single node or multiple node? Thanks....

    Read the article

  • XML parsing by DOM

    - by blackpearl
    NodeList nList2 = doc.getElementsByTagName("dep"); Map<String, List<Map<String, String>>> depMap = new HashMap<String, List<Map<String, String>>>(); for (int temp = 0; temp < nList2.getLength(); temp++) { Element el = (Element)nList2.item(temp); String type=el.getAttribute("type"); Node nNode = nList2.item(temp); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode; List<Map<String,String>> depList = new ArrayList<Map<String,String>>(); String governor = getTagValue("governor", eElement); String dependent = getTagValue("dependent", eElement); Map<String, String> govdepmap = new HashMap<String, String>(); govdepmap.put(governor, dependent); depList.add(govdepmap); List<Map<String,String>> flist = new ArrayList<Map<String,String>>(); flist.add(govdepmap); depMap.put(type, flist); } } I have the following structure in my XML file: going I Now i want to store the "idx" attribute of each "governor" and "dependent" tag. What code should I change or add?

    Read the article

  • How to jQuery plugin effects to items created later in the DOM

    - by Dan Denney
    How do I apply jQuery plugin effects to items that are created by an event? So, what I am attempting to do is have all uls throughout a site use the jquery.scroll.js plugin for styling. I currently have it working on all active uls. However, there are some category/subcategory sections. I am still new to writing any jQuery on my own and there is a leap in logic that I don't understand on applying plugins to items when they are loaded later. In the real example, users click a category from a ul and a sub category is loaded via Rails and JSON. For a light sample, I made a jsfiddle that simulates the issue that I run into. The category ul is styled correctly, but the subcategory ul doesn't pick up the styling. I'm hoping for some assistance not just in whipping up some code to fix it, but in pointing me in the direction of what I need to learn for this functionality. http://jsfiddle.net/dandenney/25R8F/1/ Thank you in advance!

    Read the article

  • Positioning decorated series of div tags on screen using offset, DOM JQUERY RELATED

    - by Calibre2010
    Hi, I am using JQuery to position a series of div tags which basically use a class inside of the tag which decorates the divs as bars. So the div is a green box based on its css specifications to the glass. I have a list of STARTING postions, a list of left coordiantes- for the starting points I wish to position my DIV say 556, 560, 600 these automatically are generated as left positions in a list I have a list of ENDING postions, a list of left coordiantes- for the ending points I wish to position my DIV say 570, 590, 610 these automatically are generated as left positions in a list now for each start and end position, the bar(green box) i want to be drawn with its appropriate width as follows. so say f is the offset or position of the start and ff the offset or position of the end : Below draws the green box based on only one start and end position LEFT. if (f.left != 0) { $("#test").html($("<div>d</div>")).css({ position: 'absolute', left: (f.left) + "px", top: (f.top + 35) + "px", width: (ff.left - f.left) + 25 + "px" }).addClass("option1"); } I am looking to loop through the list of positons in the list and draw multiple green boxs based on the positions on the screen. The above code draws just one green box from the last offset position.

    Read the article

  • How can I recurse up a DOM tree?

    - by smartdirt
    So I have a series of nested ul elements as part of a tree like below: <ul> <li> <ul> <li>1.1</li> <li>1.2</li> </ul> <ul> <li>2.1</li> <li> <ul> <li>2.2</li> </ul> </li> </ul> <ul> <li>3.1</li> <li>3.2</li> </ul> </li> </ul> Let's say when 3.1 is the selected node and when the user clicks previous the selected node should then be 2.2. The bad news is that there could be any number of levels deep. How can I find the previous node (li) in relationship to the currently selected node using jquery?

    Read the article

  • Collect DOM elements from external HTML documents

    - by sonofdelphi
    I am trying to write a report-generator to collect user-comments from a list of external HTML files. User-comments are wrapped in < span elements. Can this be done using JavaScript? Here's my attempt: function generateCommentReport() { var files = document.querySelectorAll('td a'); //Files to scan are links in an HTML table var outputWindow = window.open(); //Output browser window for report for(var i = 0; i<files.length; i++){ //Open each file in a browser window win = window.open(); win.location.href = files[i].href; //Scan opened window for 'comment's comments = win.document.getElementsByName('comment'); for(var j=0;j<comments.length;j++){ //Add to output report outputWindow.document.write(comment[i].innerHTML); } } }

    Read the article

  • DOM: how to import nodes and give them different namespace prefix

    - by thomasrutter
    I'm familiar with the DOMDocument::importNode method for importing a tree of nodes from some other document element. However, what I was wondering is if I can automatically change the namespace prefix on a tree of nodes as I import them, that is, specify a new prefix for all nodes of that namespace. Say the nodes, in their existing document, all have names like "name", "identity", and so on. When importing them into my new document they will be alongside other namespaces, so I'd like them to appear as "nicnames:name", "nicnames:identity" and so on. I'd like to be able to change this prefix programmatically so that in another context I may be able to import them as, for instance, "myprefix:name", "myprefix:identity" depending on the document they're imported into. Can anyone help me understand how to do this? Thanks

    Read the article

  • xPath insert before and after - With DOM and PHP

    - by Jens Törnell
    I need to add a class to a HTML structure. My class is called "container" and should start right after div/ul/li (the child of ul and its simblings, not grandchilds) and should end right before the closing of the same element. My whole code looks like this: <?php $content = ' <div class="sidebar-1"> <ul> <li> <h4>Title</h4> <ul> <li><a href="http://www.test.com">Test</a></li> <li><a href="http://www.test.com">Test</a></li> </ul> </li> <li> <p>Paragraf</p> </li> <li> <h4>New title</h4> <ul> <li>Some text</li> <li>Some text åäö</li> </ul> </li> </ul> </div> '; $doc = new DOMDocument(); $doc->loadHTML($content); $x = new DOMXPath($doc); $start_text = '<div class="container">'; $end_text = '</div>'; foreach($x->query('//div/ul/li') as $anchor) { $anchor->insertBefore(new DOMText($start_text),$anchor->firstChild); } echo $doc->saveXML($doc->getElementsByTagName('ul')->item(0)); ?> It works as far as i can add the class opening but not the closing element. I also get strange encoding doing this. I want the output to be the same encoding as the input. The result should be <div class="sidebar-1"> <ul> <li> <div class="content"> <h4>Title</h4> <ul> <li><a href="http://www.test.com">Test</a></li> <li><a href="http://www.test.com">Test</a></li> </ul> </div> </li> <li> <div class="content"> <p>Paragraf</p> </div> </li> <li> <div class="content"> <h4>New title</h4> <ul> <li>Some text</li> <li>Some text åäö</li> </ul> </div> </li> </ul> </div>

    Read the article

  • Parsing the Youtube API with DOM

    - by Kirk
    I'm using the Youtube API and I can retrieve the date information without a problem, but don't know how to retrieve the description information. My Code: <?php $v = "dQw4w9WgXcQ"; $url = "http://gdata.youtube.com/feeds/api/videos/". $v; $doc = new DOMDocument; $doc->load($url); $pub = $doc->getElementsByTagName("published")->item(0)->nodeValue; $desc = $doc->getElementsByTagName("media:description")->item(0)->nodeValue; echo "<b>Video Uploaded:</b> "; echo date( "F jS, Y", strtotime( $pub ) ); echo '<br>'; if (isset ($desc)) { echo "<b>Description:</b> "; echo $desc; echo '<br>'; } ?> Here's a link to the feed: http://gdata.youtube.com/feeds/api/videos/dQw4w9WgXcQ?prettyprint=true And the excerpt of code I don't know how to retrieve data from: <media:group> <media:description type='plain'>Music video by Rick Astley performing Never Gonna Give You Up. (C) 1987 PWL</media:description> </media:group> Thanks in advance.

    Read the article

  • How to select and hide all but first 5 elements in a HTML file (DOM)

    - by Zhen
    I am attempting to use coffeescript/jQuery to do the following: 1) Retrieve all the 'topics' displayed in the html (seen below) 2) Hide all the topics from display except for the first 5 listed. I tried to do the following but is not working //Retrieve the entire list of and hide all but the first 5 topics in the list $(".topics .topic")[5..-1].hide() Can someone advise me on how I can correctly retrieve the list of topics from the HTML document and subsequently hide ALL but the first 5 topics?

    Read the article

  • Detecting DOM event support in Firefox

    - by Andy E
    What's the best way to detect event support in Firefox. Opera, Internet Explorer and Safari/Chrome all support eventName in object, but Firefox doesn't. My test case is this: javascript:alert("onclick" in document.createElement("a")) Which alerts true when entered into the address bar on the aforementioned browsers, and alerts false for Firefox. I figured out a solution using typeof on an event like so: var a = document.createElement("a"); a.setAttribute("onclick", ""); alert(typeof(a.onclick) == "function"); Is there a better method of detecting event support in Firefox?

    Read the article

< Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >