Hot answers tagged

6

It's not clear how XML can be converted to JSON in a general way, because how would one deal with attributes? You happen not to have attributes in your XML, but that's just a special case. Luckily, Mathematica is a great language to write ad hoc parsers in. convert[XMLObject["Document"][{}, content_, {}]] := convert[content] convert[XMLElement[tagName_, _, ...


4

I've not been involved with XML lately, but I used to (re)define XMLObject and XMLElement to process an XML structure. It's usually received lukewarm appreciation on this site, but it seems like the sort of expression-rewriting Mathematica was built for. And in this case, it's easy: json = Block[ { XMLObject = Function[{#2} &], , XMLElement = #1 ...


3

Perhaps you can pre-process your data before feeding it in Mathematica? If so, I'd suggest you consider Data Transformer (disclaimer - I'm its developer). It offers a number of conversion settings (with sensible defaults) so you can match the data for your purposes. You can choose how to treat XM attributes, embedded text etc. It's available on the Mac ...


3

I don't know how extensible this is, but it works for your case, Cases[list, p[args:PatternSequence[___, a, _p, q, ___]] :> SequenceCases[ {args}, {a, p[x_, y_], q} :> {x, y} ], Infinity ] (* {{{1, 2}, {3, 4}, {5, 6}}} *)


2

This also works for your list, but like Jason B, I don't that is will be applicable to your XML problem. Cases[Partition[List @@ list[[1]], 3, 1], {a, u : p[_, _], q} -> u] {p[1, 2], p[3, 4], p[5, 6]}


1

ToExpression tries to get an Expression but what you've posted isn't valid Mathematica syntax. You want to use ImportString with "MathML" as the format. See this for more. mathExpr = "<math> <mfrac><mo>&DifferentialD;</mo><mrow><mo>&DifferentialD;</mo><mi>x</mi></\ mrow></mfrac> &...


1

I found a partial soulution by myself. When I used ParallelDo all kernels have the same settings. In Parallel Kernel Configuration I create a couple of new kernels. This are Master Kernels. Every one of them can have it's own proxy settings. It's possible to assigned different cells to different master kernels. ExpressionCell[Defer[2 * 2], "Input", ...


Only top voted, non community-wiki answers of a minimum length are eligible