Skip to main content
deleted 2 characters in body
Source Link
C. E.
  • 71.7k
  • 7
  • 144
  • 279

I'm going to focus on the convenience part of the question. jsoupLink can work well for a lot of situations. Let's say, for example, that we want to parse RSS. RSS is an XML format, so we can do it like this:

<< jSoupLink` root = Import["http://packagedata.net/index.php/feed", "HTMLDOM"] items = root["Select", "item"]; 

Mathematica graphics

What this shows is that using jSoupLink, we can often retrieve information with a much cleaner syntax than if we were using Mathematica's symbolic XML.

jsoupLink can also modify elements. Here's an example of how we can build an SVG, which is also an XML format, iteratively:

root = ImportString[ "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"300\" height=\"300\"></svg>", "HTMLDOM" ]; svg = First[root["Select", "svg"]]; Do[ svg[ "Append", "<circle cx=\"50\" cy=\"50\" r=\"10\" fill=\"yellow\"fill=\"blue\"/>"], {10} ]; Export["~/Desktop/test.svg", svg, "HTMLDOM"] 

If we look at this SVG file in a browser, we see the following (posted here as a PNG):

Example

All the disks are on top of each other and of the same color. We can now also use jsoupLink to shift them around and change their color:

circles = svg["Select", "circle"]; Do[ Part[circles, i]["Attribute", "cx", ToString@RandomReal[100]]; Part[circles, i]["Attribute", "cy", ToString@RandomReal[100]]; Part[circles, i]["Attribute", "fill", Image`Utilities`toHEXcolor@ColorData[97, i]]; , {i, Length[circles]} ]; ExportString[svg, "HTMLDOM"] (* Out: "<svg xmlns=\"http://www.w3.org/2000/svg\" \ xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"300\" \ height=\"300\"> <circle cx=\"39.6123\" cy=\"98.7366\" r=\"10\" fill=\"#5e81b5\" /> <circle cx=\"42.4556\" cy=\"71.0983\" r=\"10\" fill=\"#e19c24\" /> <circle cx=\"26.9683\" cy=\"9.98416\" r=\"10\" fill=\"#8fb032\" /> <circle cx=\"36.7453\" cy=\"66.7649\" r=\"10\" fill=\"#eb6235\" /> <circle cx=\"94.7156\" cy=\"21.069\" r=\"10\" fill=\"#8778b3\" /> <circle cx=\"77.1975\" cy=\"61.0884\" r=\"10\" fill=\"#c56e1a\" /> <circle cx=\"21.5307\" cy=\"24.9411\" r=\"10\" fill=\"#5d9ec7\" /> <circle cx=\"13.0563\" cy=\"62.826\" r=\"10\" fill=\"#ffbf00\" /> <circle cx=\"24.5768\" cy=\"57.8981\" r=\"10\" fill=\"#a5609d\" /> <circle cx=\"24.2052\" cy=\"21.9666\" r=\"10\" fill=\"#929600\" /> </svg>" *) 

Now it looks like this:

Example 2

I'm going to focus on the convenience part of the question. jsoupLink can work well for a lot of situations. Let's say, for example, that we want to parse RSS. RSS is an XML format, so we can do it like this:

<< jSoupLink` root = Import["http://packagedata.net/index.php/feed", "HTMLDOM"] items = root["Select", "item"]; 

Mathematica graphics

What this shows is that using jSoupLink, we can often retrieve information with a much cleaner syntax than if we were using Mathematica's symbolic XML.

jsoupLink can also modify elements. Here's an example of how we can build an SVG, which is also an XML format, iteratively:

root = ImportString[ "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"300\" height=\"300\"></svg>", "HTMLDOM" ]; svg = First[root["Select", "svg"]]; Do[ svg[ "Append", "<circle cx=\"50\" cy=\"50\" r=\"10\" fill=\"yellow\"/>"], {10} ]; Export["~/Desktop/test.svg", svg, "HTMLDOM"] 

If we look at this SVG file in a browser, we see the following (posted here as a PNG):

Example

All the disks are on top of each other and of the same color. We can now also use jsoupLink to shift them around and change their color:

circles = svg["Select", "circle"]; Do[ Part[circles, i]["Attribute", "cx", ToString@RandomReal[100]]; Part[circles, i]["Attribute", "cy", ToString@RandomReal[100]]; Part[circles, i]["Attribute", "fill", Image`Utilities`toHEXcolor@ColorData[97, i]]; , {i, Length[circles]} ]; ExportString[svg, "HTMLDOM"] (* Out: "<svg xmlns=\"http://www.w3.org/2000/svg\" \ xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"300\" \ height=\"300\"> <circle cx=\"39.6123\" cy=\"98.7366\" r=\"10\" fill=\"#5e81b5\" /> <circle cx=\"42.4556\" cy=\"71.0983\" r=\"10\" fill=\"#e19c24\" /> <circle cx=\"26.9683\" cy=\"9.98416\" r=\"10\" fill=\"#8fb032\" /> <circle cx=\"36.7453\" cy=\"66.7649\" r=\"10\" fill=\"#eb6235\" /> <circle cx=\"94.7156\" cy=\"21.069\" r=\"10\" fill=\"#8778b3\" /> <circle cx=\"77.1975\" cy=\"61.0884\" r=\"10\" fill=\"#c56e1a\" /> <circle cx=\"21.5307\" cy=\"24.9411\" r=\"10\" fill=\"#5d9ec7\" /> <circle cx=\"13.0563\" cy=\"62.826\" r=\"10\" fill=\"#ffbf00\" /> <circle cx=\"24.5768\" cy=\"57.8981\" r=\"10\" fill=\"#a5609d\" /> <circle cx=\"24.2052\" cy=\"21.9666\" r=\"10\" fill=\"#929600\" /> </svg>" *) 

Now it looks like this:

Example 2

I'm going to focus on the convenience part of the question. jsoupLink can work well for a lot of situations. Let's say, for example, that we want to parse RSS. RSS is an XML format, so we can do it like this:

<< jSoupLink` root = Import["http://packagedata.net/index.php/feed", "HTMLDOM"] items = root["Select", "item"]; 

Mathematica graphics

What this shows is that using jSoupLink, we can often retrieve information with a much cleaner syntax than if we were using Mathematica's symbolic XML.

jsoupLink can also modify elements. Here's an example of how we can build an SVG, which is also an XML format, iteratively:

root = ImportString[ "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"300\" height=\"300\"></svg>", "HTMLDOM" ]; svg = First[root["Select", "svg"]]; Do[ svg[ "Append", "<circle cx=\"50\" cy=\"50\" r=\"10\" fill=\"blue\"/>"], {10} ]; Export["~/Desktop/test.svg", svg, "HTMLDOM"] 

If we look at this SVG file in a browser, we see the following (posted here as a PNG):

Example

All the disks are on top of each other and of the same color. We can now also use jsoupLink to shift them around and change their color:

circles = svg["Select", "circle"]; Do[ Part[circles, i]["Attribute", "cx", ToString@RandomReal[100]]; Part[circles, i]["Attribute", "cy", ToString@RandomReal[100]]; Part[circles, i]["Attribute", "fill", Image`Utilities`toHEXcolor@ColorData[97, i]]; , {i, Length[circles]} ]; ExportString[svg, "HTMLDOM"] (* Out: "<svg xmlns=\"http://www.w3.org/2000/svg\" \ xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"300\" \ height=\"300\"> <circle cx=\"39.6123\" cy=\"98.7366\" r=\"10\" fill=\"#5e81b5\" /> <circle cx=\"42.4556\" cy=\"71.0983\" r=\"10\" fill=\"#e19c24\" /> <circle cx=\"26.9683\" cy=\"9.98416\" r=\"10\" fill=\"#8fb032\" /> <circle cx=\"36.7453\" cy=\"66.7649\" r=\"10\" fill=\"#eb6235\" /> <circle cx=\"94.7156\" cy=\"21.069\" r=\"10\" fill=\"#8778b3\" /> <circle cx=\"77.1975\" cy=\"61.0884\" r=\"10\" fill=\"#c56e1a\" /> <circle cx=\"21.5307\" cy=\"24.9411\" r=\"10\" fill=\"#5d9ec7\" /> <circle cx=\"13.0563\" cy=\"62.826\" r=\"10\" fill=\"#ffbf00\" /> <circle cx=\"24.5768\" cy=\"57.8981\" r=\"10\" fill=\"#a5609d\" /> <circle cx=\"24.2052\" cy=\"21.9666\" r=\"10\" fill=\"#929600\" /> </svg>" *) 

Now it looks like this:

Example 2

deleted 9 characters in body
Source Link
C. E.
  • 71.7k
  • 7
  • 144
  • 279

I'm going to focus on the convenience part of the question. jsoupLink can work well for a lot of situations. Let's say, for example, that we want to parse RSS. RSS is an XML format, so we can do it like this:

<< jSoupLink` root = Import["http://packagedata.net/index.php/feed", "HTMLDOM"] items = root["Select", "item"]; 

Mathematica graphics

What this shows is that using jSoupLink, we can often retrieve information with a much cleaner syntax than if we were using Mathematica's symbolic XML.

jsoupLink can also modify elements. Here's an example of how we can build an SVG, which is also an XML format, iteratively:

root = ImportString[ "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"300\" height=\"300\"></svg>", "HTMLDOM" ]; svg = First[root["Select", "svg"]]; Do[ svg[ "Append", "<circle cx=\"50\" cy=\"50\" r=\"10\" fill=\"yellow\"/>"], {10} ]; Export["~/Desktop/test.svg", svg, "HTMLDOM"] 

If we look at this SVG file in a browser, we see the following (posted here as a PNG):

Example

All the disks are on top of each other and of the same color. We can now also use jsoupLink to shift them around and change their color:

circles = svg["Select", "circle"]; Do[ Part[circles, i]["Attribute", "cx", ToString@RandomReal[100]]; Part[circles, i]["Attribute", "cy", ToString@RandomReal[100]]; Part[circles, i]["Attribute", "fill",  Image`Utilities`toHEXcolor[ColorData[97Image`Utilities`toHEXcolor@ColorData[97, i]]];i]]; , {i, Length[circles]} ]; ExportString[svg, "HTMLDOM"] (* Out: "<svg xmlns=\"http://www.w3.org/2000/svg\" \ xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"300\" \ height=\"300\"> <circle cx=\"39.6123\" cy=\"98.7366\" r=\"10\" fill=\"#5e81b5\" /> <circle cx=\"42.4556\" cy=\"71.0983\" r=\"10\" fill=\"#e19c24\" /> <circle cx=\"26.9683\" cy=\"9.98416\" r=\"10\" fill=\"#8fb032\" /> <circle cx=\"36.7453\" cy=\"66.7649\" r=\"10\" fill=\"#eb6235\" /> <circle cx=\"94.7156\" cy=\"21.069\" r=\"10\" fill=\"#8778b3\" /> <circle cx=\"77.1975\" cy=\"61.0884\" r=\"10\" fill=\"#c56e1a\" /> <circle cx=\"21.5307\" cy=\"24.9411\" r=\"10\" fill=\"#5d9ec7\" /> <circle cx=\"13.0563\" cy=\"62.826\" r=\"10\" fill=\"#ffbf00\" /> <circle cx=\"24.5768\" cy=\"57.8981\" r=\"10\" fill=\"#a5609d\" /> <circle cx=\"24.2052\" cy=\"21.9666\" r=\"10\" fill=\"#929600\" /> </svg>" *) 

Now it looks like this:

Example 2

I'm going to focus on the convenience part of the question. jsoupLink can work well for a lot of situations. Let's say, for example, that we want to parse RSS. RSS is an XML format, so we can do it like this:

<< jSoupLink` root = Import["http://packagedata.net/index.php/feed", "HTMLDOM"] items = root["Select", "item"]; 

Mathematica graphics

What this shows is that using jSoupLink, we can often retrieve information with a much cleaner syntax than if we were using Mathematica's symbolic XML.

jsoupLink can also modify elements. Here's an example of how we can build an SVG, which is also an XML format, iteratively:

root = ImportString[ "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"300\" height=\"300\"></svg>", "HTMLDOM" ]; svg = First[root["Select", "svg"]]; Do[ svg[ "Append", "<circle cx=\"50\" cy=\"50\" r=\"10\" fill=\"yellow\"/>"], {10} ]; Export["~/Desktop/test.svg", svg, "HTMLDOM"] 

If we look at this SVG file in a browser, we see the following (posted here as a PNG):

Example

All the disks are on top of each other and of the same color. We can now also use jsoupLink to shift them around and change their color:

circles = svg["Select", "circle"]; Do[ Part[circles, i]["Attribute", "cx", ToString@RandomReal[100]]; Part[circles, i]["Attribute", "cy", ToString@RandomReal[100]]; Part[circles, i]["Attribute", "fill",  Image`Utilities`toHEXcolor[ColorData[97, i]]]; , {i, Length[circles]} ]; ExportString[svg, "HTMLDOM"] (* Out: "<svg xmlns=\"http://www.w3.org/2000/svg\" \ xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"300\" \ height=\"300\"> <circle cx=\"39.6123\" cy=\"98.7366\" r=\"10\" fill=\"#5e81b5\" /> <circle cx=\"42.4556\" cy=\"71.0983\" r=\"10\" fill=\"#e19c24\" /> <circle cx=\"26.9683\" cy=\"9.98416\" r=\"10\" fill=\"#8fb032\" /> <circle cx=\"36.7453\" cy=\"66.7649\" r=\"10\" fill=\"#eb6235\" /> <circle cx=\"94.7156\" cy=\"21.069\" r=\"10\" fill=\"#8778b3\" /> <circle cx=\"77.1975\" cy=\"61.0884\" r=\"10\" fill=\"#c56e1a\" /> <circle cx=\"21.5307\" cy=\"24.9411\" r=\"10\" fill=\"#5d9ec7\" /> <circle cx=\"13.0563\" cy=\"62.826\" r=\"10\" fill=\"#ffbf00\" /> <circle cx=\"24.5768\" cy=\"57.8981\" r=\"10\" fill=\"#a5609d\" /> <circle cx=\"24.2052\" cy=\"21.9666\" r=\"10\" fill=\"#929600\" /> </svg>" *) 

Now it looks like this:

Example 2

I'm going to focus on the convenience part of the question. jsoupLink can work well for a lot of situations. Let's say, for example, that we want to parse RSS. RSS is an XML format, so we can do it like this:

<< jSoupLink` root = Import["http://packagedata.net/index.php/feed", "HTMLDOM"] items = root["Select", "item"]; 

Mathematica graphics

What this shows is that using jSoupLink, we can often retrieve information with a much cleaner syntax than if we were using Mathematica's symbolic XML.

jsoupLink can also modify elements. Here's an example of how we can build an SVG, which is also an XML format, iteratively:

root = ImportString[ "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"300\" height=\"300\"></svg>", "HTMLDOM" ]; svg = First[root["Select", "svg"]]; Do[ svg[ "Append", "<circle cx=\"50\" cy=\"50\" r=\"10\" fill=\"yellow\"/>"], {10} ]; Export["~/Desktop/test.svg", svg, "HTMLDOM"] 

If we look at this SVG file in a browser, we see the following (posted here as a PNG):

Example

All the disks are on top of each other and of the same color. We can now also use jsoupLink to shift them around and change their color:

circles = svg["Select", "circle"]; Do[ Part[circles, i]["Attribute", "cx", ToString@RandomReal[100]]; Part[circles, i]["Attribute", "cy", ToString@RandomReal[100]]; Part[circles, i]["Attribute", "fill", Image`Utilities`toHEXcolor@ColorData[97, i]]; , {i, Length[circles]} ]; ExportString[svg, "HTMLDOM"] (* Out: "<svg xmlns=\"http://www.w3.org/2000/svg\" \ xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"300\" \ height=\"300\"> <circle cx=\"39.6123\" cy=\"98.7366\" r=\"10\" fill=\"#5e81b5\" /> <circle cx=\"42.4556\" cy=\"71.0983\" r=\"10\" fill=\"#e19c24\" /> <circle cx=\"26.9683\" cy=\"9.98416\" r=\"10\" fill=\"#8fb032\" /> <circle cx=\"36.7453\" cy=\"66.7649\" r=\"10\" fill=\"#eb6235\" /> <circle cx=\"94.7156\" cy=\"21.069\" r=\"10\" fill=\"#8778b3\" /> <circle cx=\"77.1975\" cy=\"61.0884\" r=\"10\" fill=\"#c56e1a\" /> <circle cx=\"21.5307\" cy=\"24.9411\" r=\"10\" fill=\"#5d9ec7\" /> <circle cx=\"13.0563\" cy=\"62.826\" r=\"10\" fill=\"#ffbf00\" /> <circle cx=\"24.5768\" cy=\"57.8981\" r=\"10\" fill=\"#a5609d\" /> <circle cx=\"24.2052\" cy=\"21.9666\" r=\"10\" fill=\"#929600\" /> </svg>" *) 

Now it looks like this:

Example 2

Source Link
C. E.
  • 71.7k
  • 7
  • 144
  • 279

I'm going to focus on the convenience part of the question. jsoupLink can work well for a lot of situations. Let's say, for example, that we want to parse RSS. RSS is an XML format, so we can do it like this:

<< jSoupLink` root = Import["http://packagedata.net/index.php/feed", "HTMLDOM"] items = root["Select", "item"]; 

Mathematica graphics

What this shows is that using jSoupLink, we can often retrieve information with a much cleaner syntax than if we were using Mathematica's symbolic XML.

jsoupLink can also modify elements. Here's an example of how we can build an SVG, which is also an XML format, iteratively:

root = ImportString[ "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"300\" height=\"300\"></svg>", "HTMLDOM" ]; svg = First[root["Select", "svg"]]; Do[ svg[ "Append", "<circle cx=\"50\" cy=\"50\" r=\"10\" fill=\"yellow\"/>"], {10} ]; Export["~/Desktop/test.svg", svg, "HTMLDOM"] 

If we look at this SVG file in a browser, we see the following (posted here as a PNG):

Example

All the disks are on top of each other and of the same color. We can now also use jsoupLink to shift them around and change their color:

circles = svg["Select", "circle"]; Do[ Part[circles, i]["Attribute", "cx", ToString@RandomReal[100]]; Part[circles, i]["Attribute", "cy", ToString@RandomReal[100]]; Part[circles, i]["Attribute", "fill", Image`Utilities`toHEXcolor[ColorData[97, i]]]; , {i, Length[circles]} ]; ExportString[svg, "HTMLDOM"] (* Out: "<svg xmlns=\"http://www.w3.org/2000/svg\" \ xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"300\" \ height=\"300\"> <circle cx=\"39.6123\" cy=\"98.7366\" r=\"10\" fill=\"#5e81b5\" /> <circle cx=\"42.4556\" cy=\"71.0983\" r=\"10\" fill=\"#e19c24\" /> <circle cx=\"26.9683\" cy=\"9.98416\" r=\"10\" fill=\"#8fb032\" /> <circle cx=\"36.7453\" cy=\"66.7649\" r=\"10\" fill=\"#eb6235\" /> <circle cx=\"94.7156\" cy=\"21.069\" r=\"10\" fill=\"#8778b3\" /> <circle cx=\"77.1975\" cy=\"61.0884\" r=\"10\" fill=\"#c56e1a\" /> <circle cx=\"21.5307\" cy=\"24.9411\" r=\"10\" fill=\"#5d9ec7\" /> <circle cx=\"13.0563\" cy=\"62.826\" r=\"10\" fill=\"#ffbf00\" /> <circle cx=\"24.5768\" cy=\"57.8981\" r=\"10\" fill=\"#a5609d\" /> <circle cx=\"24.2052\" cy=\"21.9666\" r=\"10\" fill=\"#929600\" /> </svg>" *) 

Now it looks like this:

Example 2