WolframAlpha.com
WolframCloud.com
All Sites & Public Resources...
Products & Services
Wolfram|One
Mathematica
Wolfram|Alpha Notebook Edition
Programming Lab
Finance Platform
SystemModeler
Wolfram Player
Wolfram Engine
WolframScript
Enterprise Private Cloud
Enterprise Mathematica
Wolfram|Alpha Appliance
Enterprise Solutions
Corporate Consulting
Technical Consulting
Wolfram|Alpha Business Solutions
Resource System
Data Repository
Neural Net Repository
Function Repository
Wolfram|Alpha
Wolfram|Alpha Pro
Problem Generator
API
Data Drop
Products for Education
Mobile Apps
Wolfram Player
Wolfram Cloud App
Wolfram|Alpha for Mobile
Wolfram|Alpha-Powered Apps
Services
Paid Project Support
Wolfram U
Summer Programs
All Products & Services »
Technologies
Wolfram Language
Revolutionary knowledge-based programming language.
Wolfram Cloud
Central infrastructure for Wolfram's cloud products & services.
Wolfram Science
Technology-enabling science of the computational universe.
Wolfram Notebooks
The preeminent environment for any technical workflows.
Wolfram Engine
Software engine implementing the Wolfram Language.
Wolfram Natural Language Understanding System
Knowledge-based broadly deployed natural language.
Wolfram Data Framework
Semantic framework for real-world data.
Wolfram Universal Deployment System
Instant deployment across cloud, desktop, mobile, and more.
Wolfram Knowledgebase
Curated computable knowledge powering Wolfram|Alpha.
All Technologies »
Solutions
Engineering, R&D
Aerospace & Defense
Chemical Engineering
Control Systems
Electrical Engineering
Image Processing
Industrial Engineering
Mechanical Engineering
Operations Research
More...
Finance, Statistics & Business Analysis
Actuarial Sciences
Bioinformatics
Data Science
Econometrics
Financial Risk Management
Statistics
More...
Education
All Solutions for Education
Trends
Machine Learning
Multiparadigm Data Science
Internet of Things
High-Performance Computing
Hackathons
Software & Web
Software Development
Authoring & Publishing
Interface Development
Web Development
Sciences
Astronomy
Biology
Chemistry
More...
All Solutions »
Learning & Support
Learning
Wolfram Language Documentation
Fast Introduction for Programmers
Wolfram U
Videos & Screencasts
Wolfram Language Introductory Book
Webinars & Training
Summer Programs
Books
Need Help?
Support FAQ
Wolfram Community
Contact Support
Premium Support
Paid Project Support
Technical Consulting
All Learning & Support »
Company
About
Company Background
Wolfram Blog
Events
Contact Us
Work with Us
Careers at Wolfram
Internships
Other Wolfram Language Jobs
Initiatives
Wolfram Foundation
MathWorld
Computer-Based Math
A New Kind of Science
Wolfram Technology for Hackathons
Student Ambassador Program
Wolfram for Startups
Demonstrations Project
Wolfram Innovator Awards
Wolfram + Raspberry Pi
Summer Programs
More...
All Company »
Search
WOLFRAM COMMUNITY
Connect with users of Wolfram technologies to learn, solve problems and share ideas
Join
Sign In
Dashboard
Groups
People
Message Boards
Answer
(
Unmark
)
Mark as an Answer
GROUPS:
Computer Science
Import and Export
Interface Construction
Wolfram Language
Wolfram High School Summer Camp
4
Timothy Bilik
[WSC20] Making an XML Formatter/Visualizer
Timothy Bilik, High School Student
Posted
9 months ago
1782 Views
|
1 Reply
|
5 Total Likes
Follow this post
|
Introduction to XML
According to the W3C, XML (Extensible Markup Language) is a "simple, very flexible text format derived from SGML" that is "playing an increasingly important role in the exchange of a wide variety of data on the Web and elsewhere." Almost every webpage has XML embedded in it in a form known as HTML. Some image files, such as SVG (scalable vector graphics), also use the XML format. The main construct of XML is simple. XML contains nodes known as elements, elements can have attributes, and elements can contain children. Children can include text or more elements.
<bookstore>
<book category=”children”>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category=”web”>
<title>Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
Above is a simple example of XML. The root element is bookstore, and bookstore contains two book elements. The book elements each have attribute data labelled as "category". The book elements contain title, author, year, and price elements, which each contain text respectively. XML doesn't have a limit on how much you can nest elements. Some XML files will have simple nesting, and some will have much more complicated nesting.
The following is the Ubuntu logo as a scalable vector graphic:
R
e
s
o
u
r
c
e
F
u
n
c
t
i
o
n
[
"
S
V
G
I
m
p
o
r
t
"
]
[
"
/
h
o
m
e
/
t
b
i
l
i
k
/
u
b
u
n
t
u
.
s
v
g
"
]
I
n
[
]
:
=
O
u
t
[
]
=
The following is a Ford Focus as a scalable vector graphic:
R
e
s
o
u
r
c
e
F
u
n
c
t
i
o
n
[
"
S
V
G
I
m
p
o
r
t
"
]
[
"
/
h
o
m
e
/
t
b
i
l
i
k
/
F
o
r
d
F
o
c
u
s
.
s
v
g
"
]
I
n
[
]
:
=
O
u
t
[
]
=
This is a representation of the node nesting in the Ubuntu Logo vector:
I
m
p
o
r
t
[
"
/
h
o
m
e
/
t
b
i
l
i
k
/
u
b
u
n
t
u
.
s
v
g
"
,
"
X
M
L
"
]
/
/
E
x
p
r
e
s
s
i
o
n
G
r
a
p
h
I
n
[
]
:
=
O
u
t
[
]
=
The Ford Focus Graphic has so much node nesting, Wolfram doesn't show the Expression Graph:
I
m
p
o
r
t
[
"
/
h
o
m
e
/
t
b
i
l
i
k
/
F
o
r
d
F
o
c
u
s
.
s
v
g
"
,
"
X
M
L
"
]
/
/
E
x
p
r
e
s
s
i
o
n
G
r
a
p
h
I
n
[
]
:
=
G
r
a
p
h
V
e
r
t
e
x
c
o
u
n
t
:
1
0
3
9
4
E
d
g
e
c
o
u
n
t
:
1
0
3
9
3
T
y
p
e
:
u
n
d
i
r
e
c
t
e
d
g
r
a
p
h
C
o
n
n
e
c
t
e
d
g
r
a
p
h
:
T
r
u
e
A
c
y
c
l
i
c
g
r
a
p
h
:
T
r
u
e
O
u
t
[
]
=
Wolfram's Import[] function can import a file as XML, as shown in the last two examples. When a file is imported as XML, Wolfram returns an XMLObject Document. XMLObject Documents contain two parameters. The first parameter contains the XML Declaration and/or Doctype. These state the standard of XML being used. The second parameter is an XMLElement. XMLElement contains 3 parameters. XMLElement contains the element name (often known as a tag), a list of rules that represent the attributes, and a list that represents the children of the element.
How can XMLElements be formatted/visualized in Wolfram?
One approach I had to formatting XMLElements was to use recursion.
The function takes in an XMLElement. It will print the tag, attributes, and children. If one of the children is an XMLElement, the function will call itself, increasing the nesting by 1. The "nest" argument controls indentation:
X
M
L
F
o
r
m
a
t
t
e
r
[
e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k
T
.
R
a
y
y
e
a
r
2
0
0
3
p
r
i
c
e
3
9
.
9
5
This may be good for simple XML files, but the output will get larger and more complicated if the XML gets larger and further nested. Luckily, Wolfram has functions to allow for collapsed output. The OpenerView function is one function that does this.
Here is a simple OpenerView example. It takes a list of 2 elements. The first element is visible, the second one is collapsed:
O
p
e
n
e
r
V
i
e
w
[
{
a
,
b
}
]
I
n
[
]
:
=
a
b
O
u
t
[
]
=
If multiple things needs to be visible or collapsed, Column[] can be used:
O
p
e
n
e
r
V
i
e
w
[
{
C
o
l
u
m
n
[
{
a
,
b
,
c
}
]
,
C
o
l
u
m
n
[
{
d
,
e
,
f
}
]
}
]
I
n
[
]
:
=
a
b
c
O
u
t
[
]
=
I also found a better solution to recursion when it comes to nesting. Instead of recursion, I can just write my own function that replaces XMLElement at all levels. Replacing heads at all levels in Wolfram is very easy with the Replace[] function.
This will replace XMLElement with MyXMLElement at all levels:
R
e
p
l
a
c
e
[
x
m
l
E
l
m
,
X
M
L
E
l
e
m
e
n
t
M
y
X
M
L
E
l
e
m
e
n
t
,
I
n
f
i
n
i
t
y
,
H
e
a
d
s
T
r
u
e
]
Before I show the MyXMLElement function I created, I would like to show some of the variables and functions it depends on.
These styling variables need to be declared:
b
a
s
e
S
t
y
l
e
=
{
F
o
n
t
F
a
m
i
l
y
"
S
o
u
r
c
e
S
a
n
s
P
r
o
"
,
F
o
n
t
S
i
z
e
1
4
}
;
t
a
g
S
t
y
l
e
=
J
o
i
n
[
b
a
s
e
S
t
y
l
e
,
{
B
o
l
d
,
O
r
a
n
g
e
}
]
;
a
t
t
S
t
y
l
e
=
J
o
i
n
[
b
a
s
e
S
t
y
l
e
,
{
G
r
a
y
}
]
;
I
n
[
]
:
=
This function will find hexadecimal color codes in a string. A hexadecimal color code contains a pound sign which is followed by 3 or 6 hexadecimal characters:
H
e
x
S
t
r
i
n
g
P
a
t
t
e
r
n
:
=
{
"
#
"
~
~
H
e
x
a
d
e
c
i
m
a
l
C
h
a
r
a
c
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=
=
=
L
i
s
t
,
S
t
r
i
n
g
R
i
f
f
l
e
[
K
e
y
s
[
#
]
,
"
⁃
"
]
,
K
e
y
s
[
#
]
]
,
"
:
"
,
V
a
l
u
e
s
[
#
]
]
,
a
t
t
S
t
y
l
e
]
&
/
@
a
t
t
r
i
b
u
t
e
s
]
}
,
I
f
[
L
e
n
g
t
h
[
c
h
i
l
d
r
e
n
]
0
,
C
o
l
u
m
n
[
v
i
s
i
b
l
e
]
,
O
p
e
n
e
r
V
i
e
w
[
{
C
o
l
u
m
n
[
v
i
s
i
b
l
e
]
,
C
o
l
u
m
n
[
I
f
[
H
e
a
d
[
#
]
=
=
=
S
t
r
i
n
g
,
S
t
y
l
e
[
#
,
b
a
s
e
S
t
y
l
e
]
,
#
]
&
/
@
C
a
s
e
s
[
c
h
i
l
d
r
e
n
,
x
_
_
_
/
;
!
(
H
e
a
d
[
x
]
=
=
=
X
M
L
O
b
j
e
c
t
[
"
C
o
m
m
e
n
t
"
]
)
]
]
}
,
F
r
a
m
e
M
a
r
g
i
n
s
1
0
]
]
]
I
n
[
]
:
=
This can look a bit daunting, but it's easier if it's broken down. MyXMLElement takes the exact same parameters that XMLElement does: tag name, attributes, and children. The module contains one variable in it's brackets: visible. As the name implies, this will generate the non-collapsed part of the OpenerView. It puts the tag name and attributes into its own row. Two things are worth noting in the visible variable: the RGBColor[] function, and the StringRiffle[] function. If a hexadecimal color code is found in an attribute (color codes are often found in HTML, SVG, and other formats), RGBColor[] will show that color in a square adjacent to the attribute. The StringRifle[] function has to do with XML namespaces. The usage of XML namespaces is outside the scope of this essay, but if XML namespaces exist in a tag or attribute, the tag or attribute key becomes a List of Strings rather than an independent String when imported as an XMLObject. StringRiffle[] will join the lists with unicode dashes in between. The code in the module generates an OpenerView if an element has children. The children are slightly modified, as XML comments are removed, and non-element children are given the base style. The "FrameMargins" option is mainly for aesthetics.
Without further ado, here is a demonstration:
e
x
a
m
p
l
e
X
M
L
=
I
m
p
o
r
t
[
"
/
h
o
m
e
/
t
b
i
l
i
k
/
u
b
u
n
t
u
.
s
v
g
"
,
"
X
M
L
"
]
;
R
e
p
l
a
c
e
[
e
x
a
m
p
l
e
X
M
L
[
[
2
]
]
,
X
M
L
E
l
e
m
e
n
t
M
y
X
M
L
E
l
e
m
e
n
t
,
I
n
f
i
n
i
t
y
,
H
e
a
d
s
T
r
u
e
]
I
n
[
]
:
=
s
v
g
h
t
t
p
:
/
/
w
w
w
.
w
3
.
o
r
g
/
2
0
0
0
/
x
m
l
n
s
/
⁃
x
m
l
n
s
:
h
t
t
p
:
/
/
w
w
w
.
w
3
.
o
r
g
/
2
0
0
0
/
s
v
g
h
t
t
p
:
/
/
w
w
w
.
w
3
.
o
r
g
/
2
0
0
0
/
x
m
l
n
s
/
⁃
x
l
i
n
k
:
h
t
t
p
:
/
/
w
w
w
.
w
3
.
o
r
g
/
1
9
9
9
/
x
l
i
n
k
v
i
e
w
B
o
x
:
-
7
0
-
7
0
1
4
0
1
4
0
O
u
t
[
]
=
To make using this functionality slightly less tedious, I wrote a function that will either take an XML file or XMLObject and will do the head replacement:
X
M
L
2
O
p
e
n
e
r
V
i
e
w
[
i
n
p
u
t
_
]
:
=
M
o
d
u
l
e
[
{
x
m
l
O
b
j
=
W
h
i
c
h
[
H
e
a
d
[
i
n
p
u
t
]
=
=
=
S
t
r
i
n
g
&
&
F
i
l
e
E
x
i
s
t
s
Q
[
i
n
p
u
t
]
,
I
m
p
o
r
t
[
i
n
p
u
t
,
"
X
M
L
"
]
,
H
e
a
d
[
i
n
p
u
t
]
=
=
=
X
M
L
O
b
j
e
c
t
[
"
D
o
c
u
m
e
n
t
"
]
,
i
n
p
u
t
,
T
r
u
e
,
1
]
}
,
I
f
[
x
m
l
O
b
j
=
=
=
1
,
R
e
t
u
r
n
[
F
a
i
l
u
r
e
[
"
I
n
v
a
l
i
d
I
n
p
u
t
"
,
<
|
|
>
]
]
]
;
R
e
p
l
a
c
e
[
x
m
l
O
b
j
[
[
2
]
]
,
X
M
L
E
l
e
m
e
n
t
M
y
X
M
L
E
l
e
m
e
n
t
,
I
n
f
i
n
i
t
y
,
H
e
a
d
s
T
r
u
e
]
]
I
n
[
]
:
=
Using XML2OpenerView with a filename:
X
M
L
2
O
p
e
n
e
r
V
i
e
w
[
"
/
h
o
m
e
/
t
b
i
l
i
k
/
u
b
u
n
t
u
.
s
v
g
"
]
I
n
[
]
:
=
s
v
g
h
t
t
p
:
/
/
w
w
w
.
w
3
.
o
r
g
/
2
0
0
0
/
x
m
l
n
s
/
⁃
x
m
l
n
s
:
h
t
t
p
:
/
/
w
w
w
.
w
3
.
o
r
g
/
2
0
0
0
/
s
v
g
h
t
t
p
:
/
/
w
w
w
.
w
3
.
o
r
g
/
2
0
0
0
/
x
m
l
n
s
/
⁃
x
l
i
n
k
:
h
t
t
p
:
/
/
w
w
w
.
w
3
.
o
r
g
/
1
9
9
9
/
x
l
i
n
k
v
i
e
w
B
o
x
:
-
7
0
-
7
0
1
4
0
1
4
0
O
u
t
[
]
=
Using XML2OpenerView with an XMLObject:
X
M
L
2
O
p
e
n
e
r
V
i
e
w
[
e
x
a
m
p
l
e
X
M
L
]
I
n
[
]
:
=
s
v
g
h
t
t
p
:
/
/
w
w
w
.
w
3
.
o
r
g
/
2
0
0
0
/
x
m
l
n
s
/
⁃
x
m
l
n
s
:
h
t
t
p
:
/
/
w
w
w
.
w
3
.
o
r
g
/
2
0
0
0
/
s
v
g
h
t
t
p
:
/
/
w
w
w
.
w
3
.
o
r
g
/
2
0
0
0
/
x
m
l
n
s
/
⁃
x
l
i
n
k
:
h
t
t
p
:
/
/
w
w
w
.
w
3
.
o
r
g
/
1
9
9
9
/
x
l
i
n
k
v
i
e
w
B
o
x
:
-
7
0
-
7
0
1
4
0
1
4
0
O
u
t
[
]
=
Making the XML Visualizer Dynamic
Since the beginning of the project, I wanted to have a two-way transformation between the XML Text and the Visualized XML. More specifically, I wanted to be able to modify the contents of the visualized XML, and then to have function that would be able to scrape it and turn it back into XML Text. To allow for the modification of the visualized XML, I made every element, attribute, and child a button. It can be clicked on to open up an input field where the contents can be changed. Here is the modified MyXMLElement function that allows for this functionality.
M
y
X
M
L
E
l
e
m
e
n
t
[
t
i
t
l
e
_
,
a
t
t
r
i
b
u
t
e
s
_
L
i
s
t
,
c
h
i
l
d
r
e
n
_
L
i
s
t
]
:
=
M
o
d
u
l
e
[
{
v
i
s
i
b
l
e
=
M
o
d
u
l
e
[
{
y
=
#
[
[
1
]
]
}
,
R
o
w
[
{
B
u
t
t
o
n
[
S
t
y
l
e
[
D
y
n
a
m
i
c
[
y
]
,
#
[
[
2
]
]
]
,
C
r
e
a
t
e
D
i
a
l
o
g
[
I
n
p
u
t
F
i
e
l
d
[
D
y
n
a
m
i
c
[
y
]
,
S
t
r
i
n
g
]
]
,
A
p
p
e
a
r
a
n
c
e
N
o
n
e
]
,
"
"
,
D
y
n
a
m
i
c
[
I
f
[
S
t
r
i
n
g
C
o
n
t
a
i
n
s
Q
[
y
,
H
e
x
S
t
r
i
n
g
P
a
t
t
e
r
n
]
,
R
G
B
C
o
l
o
r
[
S
t
r
i
n
g
C
a
s
e
s
[
y
,
H
e
x
S
t
r
i
n
g
P
a
t
t
e
r
n
]
[
[
1
]
]
]
,
"
"
]
]
}
]
]
&
/
@
J
o
i
n
[
{
{
I
f
[
H
e
a
d
[
t
i
t
l
e
]
=
=
=
L
i
s
t
,
S
t
r
i
n
g
R
i
f
f
l
e
[
t
i
t
l
e
,
"
⁃
"
]
,
t
i
t
l
e
]
,
t
a
g
S
t
y
l
e
}
}
,
L
i
s
t
[
S
t
r
i
n
g
J
o
i
n
[
I
f
[
H
e
a
d
[
K
e
y
s
[
#
]
]
=
=
=
L
i
s
t
,
S
t
r
i
n
g
R
i
f
f
l
e
[
K
e
y
s
[
#
]
,
"
⁃
"
]
,
K
e
y
s
[
#
]
]
,
"
:
"
,
V
a
l
u
e
s
[
#
]
]
,
a
t
t
S
t
y
l
e
]
&
/
@
a
t
t
r
i
b
u
t
e
s
]
}
,
I
f
[
L
e
n
g
t
h
[
c
h
i
l
d
r
e
n
]
0
,
C
o
l
u
m
n
[
v
i
s
i
b
l
e
]
,
O
p
e
n
e
r
V
i
e
w
[
{
C
o
l
u
m
n
[
v
i
s
i
b
l
e
]
,
C
o
l
u
m
n
[
I
f
[
H
e
a
d
[
#
]
=
=
=
S
t
r
i
n
g
,
M
o
d
u
l
e
[
{
y
=
#
}
,
B
u
t
t
o
n
[
S
t
y
l
e
[
D
y
n
a
m
i
c
[
y
]
,
b
a
s
e
S
t
y
l
e
]
,
C
r
e
a
t
e
D
i
a
l
o
g
[
I
n
p
u
t
F
i
e
l
d
[
D
y
n
a
m
i
c
[
y
]
,
S
t
r
i
n
g
]
]
,
A
p
p
e
a
r
a
n
c
e
N
o
n
e
]
]
,
#
]
&
/
@
C
a
s
e
s
[
c
h
i
l
d
r
e
n
,
x
_
_
_
/
;
!
(
H
e
a
d
[
x
]
=
=
=
X
M
L
O
b
j
e
c
t
[
"
C
o
m
m
e
n
t
"
]
)
]
]
}
,
F
r
a
m
e
M
a
r
g
i
n
s
1
0
]
]
]
This isn't largely different, except for the fact that some things are now dynamic. This likely won't execute easily in the cloud, so here is a screenshot of the functionality. In the photo, I had clicked on the "path" tag, and a window with an input field popped up. The contents of the input field will modify the visualizer.
Now that the visualizer can be modified, a scraper function will be needed to turn it back into XML Text. With replace functionality and pattern matching, the visualized XML can be turned back into an XMLObject with relative ease. Before I show the scraping function, these functions are required for the scraping functionality. Both of these functions are related to parsing the tag and attributes that were modified in the visualizer.
Attribute Parser:
S
t
r
i
n
g
2
A
t
t
r
i
b
u
t
e
s
[
x
_
L
i
s
t
]
:
=
(
I
f
[
S
t
r
i
n
g
C
o
n
t
a
i
n
s
Q
[
#
[
[
1
]
]
,
"
⁃
"
]
,
S
t
r
i
n
g
S
p
l
i
t
[
#
[
[
1
]
]
,
"
⁃
"
]
,
#
[
[
1
]
]
]
#
[
[
2
]
]
)
&
/
@
S
t
r
i
n
g
S
p
l
i
t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m
n
[
y
_
]
}
,
_
_
_
]
X
M
L
E
l
e
m
e
n
t
[
S
t
r
i
n
g
2
T
a
g
[
F
i
r
s
t
[
x
]
]
,
S
t
r
i
n
g
2
A
t
t
r
i
b
u
t
e
s
[
D
r
o
p
[
x
,
1
]
]
,
y
]
;
x
m
l
O
b
j
[
[
2
]
]
=
x
m
l
O
b
j
[
[
2
]
]
/
/
.
C
o
l
u
m
n
[
x
_
]
X
M
L
E
l
e
m
e
n
t
[
S
t
r
i
n
g
2
T
a
g
[
F
i
r
s
t
[
x
]
]
,
S
t
r
i
n
g
2
A
t
t
r
i
b
u
t
e
s
[
D
r
o
p
[
x
,
1
]
]
,
{
}
]
;
x
m
l
O
b
j
]
I
n
[
]
:
=
Similar to XML2OpenerView, it takes an XMLObject or filename. The main reason for this is to retrieve XML Declaration/Doctype data, which is not embedded in the visualization. As stated, the function then uses various replacements and patterns to scrape the visualized XML. There is nothing particularly unique about this process, other than Setting[x]. This converts everything from dynamic to the latest static value at the time of execution. The function returns an XMLObject, which can be easily exported to XML Text using one of Wolfram's export functions.
Exporting via the ExportString function:
E
x
p
o
r
t
S
t
r
i
n
g
[
%
,
"
X
M
L
"
]
Further Improvements
Some XML functionality is not supported by my code, such as CDATA. For highly nested XML, the collapsed format can be tedious, so I would like to make it so that some (but not all) OpenerViews are open by default. More testing needs to be done as well in general.
Keywords
XML: Extensible Markup Language, a documenting format
◼
HTML: Hypertext Markup Language, a form of XML that is used for webpage structure
◼
SVG: Scalable Vector Graphics, a form of XML that is used for images
◼
Hexadecimal: a numbering system that uses base-16. Uses the numbers in base 10 along with the letters a through f.
◼
POSTED BY:
Timothy Bilik
Answer
Mark as an Answer
Reply
|
Flag
1 Reply
Sort By:
Replies
Likes
Recent
1
Stephen Schroeder
Stephen Schroeder, Wolfram Research
Posted
9 months ago
So cool, this project turned out so well! Great essay that was clear and informative!
POSTED BY:
Stephen Schroeder
Answer
Mark as an Answer
Reply
|
Flag
Reply to this discussion
in reply to
Add Notebook
Community posts can be styled and formatted using the
Markdown syntax
.
Tag limit exceeded
Note: Only the first five people you tag will receive an email notification; the other tagged names will appear as links to their profiles.
Publish anyway
Cancel
Reply Preview
Attachments
Remove
Add a file to this post
Follow this discussion
or
Discard
Group Abstract
Be respectful. Review our
Community Guidelines
to understand your role and responsibilities.
Community Terms of Use
Feedback
Enable JavaScript to interact with content and submit forms on Wolfram websites.
Learn how »