Sunday 15 May 2011

Searching through XML within an HTML using JavaScript -


I will try to explain it as little as possible. I have IFrame tags in which there is XML database on which there is a textfield and a button on which I would like to add a function that receives value from the textfield and display results that match the queries entered only for a specific XML tag. Does.

How will I be going about doing this? I know how to get value, but in the part in which I really have to display only the results matched, I do not know how to do it.

If anyone cares, this is a college project, they just want to see that we know some javascript basics. Here is the page where I would like to see the above mentioned:

In your iframe To apply the XSLT stylesheet near the browser, there is an XML with processing instructions telling the browser that replaces the HTML with HTML from the table. Thus if you were using the IFrame document with Javascript, then you will not be able to get the XML element, but the result of XSLT conversion is HTML document.

On that basis, I feel that you have two options:

  1. You can keep the XSLT unchanged and hide the table row in the HTML document in iframe Do the script.
  2. You need to add a parameter or two to customize the XSLT by filtering and then you need to use the highlighted API by applying the XSLT with the parameter set. And you need to change the contents of the iframe with new conversion results.

    In either way, "search through XML" will not use Javascript as you would search through HTML and the second XSLT will search XML as before.

    Access the document of iframe via javascript,

      var iframeDoc = window.frames.dsoChamps.document; Reach the table with   

    then

      var table = iframeDoc.getElementsByTagName [0] [0];   

    Then you can check whether the table.rows [i] .cells [j] .textcontent from the table.rows collection The price you want is table.rows [i] .style.display = 'none'; by setting it up, you can just set the table.rows [i] to show it again. Style display = ''; As an alternative you can define only one CSS class and set the className of the rows to unset it to show the rows again.

    One of the warnings is that text content is only supported in recent IE versions, for older people you have to check out innerText .

    For the option to implement XSLT with Javascript, inside Mozilla, you have the same API in Opera, Safari, Chrome, with all IE versions you need to use separate API is.

    For XSLT, I for this at least one thead header row, this is a cleaner document structure and simplifies your work to find rows, such as That you can search table.tbodies [0] .rows and ignore header row

No comments:

Post a Comment