scripting / Scripting-News

I'm starting to use GitHub for work on my blog. Why not? It's got good communication and collaboration tools. Why not hook it up to a blog?
117 stars 10 forks source link

A sensible XML viewer for browser JavaScript? #226

Open scripting opened 2 years ago

scripting commented 2 years ago

When you view a normal XML file in the browser, Chrome gives you a simple, readable XML viewer. I want to be able to invoke that viewer from a JavaScript app running in the browser. Some kind of JavaScript call like window.xmlViewer (xmltext); The only other option is to rewrite it from scratch, which I'm open to doing but would rather not. Does anyone know if such a thing exists?

mcenirm commented 2 years ago

The magic seems to be in https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/xml/DocumentXMLTreeViewer.js

Looking at the sibling source files, I think the browser engine runs the javascript against the source XML document to transform it into a styled HTML document. I did not find any glaring items in the javascript that would prevent it from being used in the situation you need. To be clear, this wouldn't be directly what you asked for, but it would be somewhere in between an existing browser API and redoing from scratch.

mikeptweet commented 2 years ago

You can set the url to a data format such as

data:text/xml;,<xml><name>this is a test</name></xml>

You should be able to do this programatically as well as just entering it in the browser address bar

mterenzio commented 2 years ago

Perhaps an XSLT, but this assumes you know the possible elements allowed in the XML. Very under-utilized feature that most browsers still support.

https://www.w3schools.com/xml/xsl_client.asp