Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1263
  • Last Modified:

Display XML in IFRAME dinamically

Hi!

I'd like to display XML in IFRAME dinamically in expandable way, like it appears when you open XML file in IE. It has to look like XML preview: user edit XML in TEXTAREA element, clicks Preview button and the TEXTAREA's content should be displayed in IFRAME ( or any other element) in expandable, structured way.

xml_preview.document.body.innerHTML = xml_edit.innerHTML;

The above line only copies the content, but does not treat it as XML.

Any ideas will be appreciated,
Jigit
0
Jigit
Asked:
Jigit
  • 9
  • 8
1 Solution
 
ZylochCommented:
Hi

XML is opened that way by default... just have something like this:

<iframe src="something.xml" name="iframename"> and it's fine... If you want it changed in the middle, just use iframename.location.href="newxml.xml"
Regards,
Zyloch
0
 
ZylochCommented:
Ahh, I see. You probably should create a temporary file for them to edit. That's the easiest way.  

Regards
1
 
JigitAuthor Commented:
Zyloch, can you give a piece of code doing it?

Thanks,
Jigit
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ZylochCommented:
Do you have a server-side language you can use?
0
 
JigitAuthor Commented:
Unfortunately, everything must be done on the client - IE 5.5 or higher.
0
 
ZylochCommented:
Give me a little time--I'm working on it
0
 
JigitAuthor Commented:
Zyloch, take your time, but it's pretty urgent. BTW, point were doubled.
0
 
JigitAuthor Commented:
I solved it currently using server-side approach, which works pretty well. Unless there are client-side solutions, this question will be closed.
0
 
ZylochCommented:
Ah ok, sorry about not finishing it on time. I had a <div> solution that worked ok, but I was trying to change it into a table one for presentation purposes. You should just refund you points ;)
0
 
JigitAuthor Commented:
Zyloch, you don't have to be sorry. I appriciate your efforts. Do you really have a client-side only solution? I'd like to see it and you will be rewarded appropriately.
0
 
ZylochCommented:
This is actually something really rough. I had a better version, but by accident, I used the same one to try to recreate the table one, so this is pretty rough and pretty quickly done with some flaws that need to be worked on, but it shows a basic tree layout most of the time. The collapsing doesn't work yet in this example (it did in the original), but just to show it's something like this:
-------------------------------------------------
<style>
a {text-decoration:none;}
</style>
<script>
function convertToXMLFormat(transformText,target,level) {
   if (transformText=="") {return true;}

   if (level==0) {
      target.innerHTML="";
   }

   var m = transformText.match(/<(.*)>.*?<\/\1>?/g);
   var numMatch = 0;

   if (m!=null) {
      numMatch = m.length;
   }
   else {
      target.innerHTML+="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
      target.innerHTML+="<b>"+transformText+"<b><br>";
   }

   for (var j=0;j<numMatch;j++) {
      var testPattern = /<(.*)?>(.+)?<\/\1>?/g.exec(m[j]);

      target.innerHTML+="<div>"
      for (var i=0;i<level;i++){target.innerHTML+="<span style=\"visibility:hidden;\">&mdash;</span>"}
      target.innerHTML+="<a href=\"javascript:toggleTree("+level+","+target+")\"";
      target.innerHTML+="-&nbsp;&nbsp;"
      target.innerHTML+="&lt;"+testPattern[1]+"&gt;<br>";
      convertToXMLFormat(testPattern[2],target,level+1);
      for (var i=0;i<level;i++){target.innerHTML+="<span style=\"visibility:hidden;\">&mdash;</span>"}
      target.innerHTML+="&lt;/"+testPattern[1]+"&gt;</td></tr></table><br>";
   }
}
</script>

<div id="xmlShow">
</div>

<textarea id="hey"></textarea>
<input type="button" value="Test" onclick="convertToXMLFormat(document.getElementById('hey').value,document.getElementById('xmlShow'),0);">
0
 
JigitAuthor Commented:
Zyloch, I'm impressed by the code. It seems, that toggleTree function is missing. In addition, it ignores XML tags having attributes. Can we resolve it?

Thanks,
Jigit
0
 
ZylochCommented:
Yes, I've noticed that. I had a slightly better version, but being my idiotic self, I erased it in favor of trying to go with tables... It can probably be resolved (i.e. better use of regex). I admit the above code is a very rough draft that I've just drawn up because the tables thing didn't pan out.
0
 
JigitAuthor Commented:
Zyloch, would you be so kind to publish final solution? It will be my pleasure to accept your answer.
0
 
ZylochCommented:
Sorry, I was on vacation. I'll get to it as soon as I get back
0
 
ZylochCommented:
Dang, school almost began, I crammed for summer reading and didn't expect 3 essays first week back, jeez... anyways, thanks for the positive feedback, it's making me feel bad that I couldn't get it out in time, so I'm going to keep working on it when I have free time.
0
 
JigitAuthor Commented:
Zyloch, you are welcome. I'll be waiting for your solution.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 9
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now