DeltaXML / vscode-xpath-notebook

Visual Studio Code notebook extension for XPath 3.1
MIT License
22 stars 1 forks source link

Add XPath Notebook Samples #2

Open pgfearo opened 3 years ago

pgfearo commented 3 years ago
RandomFractals commented 3 years ago

re: https://github.com/DeltaXML/vscode-xpath-notebook/tree/main/samples/notebooks/gdpbycountry

I would suggest to forgo /samples directory and have the top-level /notebooks directory instead. it's more standard in data viz and data science community.

Also, if you want to get better GDP data, see this kaggle dataset: https://www.kaggle.com/tunguz/country-regional-and-world-gdp or search for others there.

RandomFractals commented 3 years ago

I might use that dataset for providing XPath notebook example in my data table renderer extension here: https://github.com/RandomFractals/vscode-data-table/issues/69

RandomFractals commented 3 years ago

@pgfearo how do I specify xml data source?

I copied your notebook and xml data, and placed them in the same folder:

image

I think docs need an example for this part: https://github.com/DeltaXML/vscode-xpath-notebook#step-3-setup-the-xpath-evaluation-context

pgfearo commented 3 years ago

@RandomFractals The XML (or JSON) data source for the XPath Notebook is the most recent (non-notebook) file opened in Visual Studio Code. This should be intuitive to users of popular XML tools such Oxygen XML's XPath Builder View - but perhaps less obvious to others. I will try to make this clearer in the documentation.

If this most recent file opened in VS Code was not valid XML or JSON then the data source is empty (i.e. there is no XPath context item) but you can still execute XPath expressions that don't rely on a data source being set as the context.

I do intend to add other ways to bind the Notebook to a data source in a transient way. But this requires more advanced Notebook features and will therefore have to wait until Visual Studio Code's Notebook API is fully implemented in the stable release

For a more persistent method for binding a data source, the user should probably use the XPath doc() or json-doc() functions in a cell that contains an XPath Prolog to assign that source to an XPath variable for other cells to use. For example:

Cell 1

  variable = mydata %
  doc('gdpdata.xml`)

Cell 2

  for $countries in $mydata 
  return $countries...

A complication is that prefix/URI bindings for XML namespace are currently only extracted from the XPath Notebook data source...

RandomFractals commented 3 years ago

@pgfearo I looked at your updated docs and notebook examples.

Tried loading xml data again, and still get errors:

image

Could you please provide a clear example of how to load xml data from a file location relative to XBook?

Thanks!

pgfearo commented 3 years ago

You have followed the example correctly, as you can see in the specification fn:doc.

This could either be a bug (most likely) or an issue with the XML data source. The JSON.parse error message in the Console seems very relevant. I develop this extension on MacOS so this could be a Windows issue...I will see if I can reproduce this. Windows file paths with their backslash chars can cause similar error messages.

Do you get a similar error for other types of XML data files? Is there hexadecimal content in the XML by any chance?

RandomFractals commented 3 years ago

that data file is here: https://github.com/RandomFractals/vscode-data-table/blob/main/data/world-gdp.xml

It doesn't have hexadecimal content. I was able to load it with fast-xml-parser just fine.

Please ignore the data:table JSON.parse errors you see there. Those are coming from my extension, which tries to parse cell output as json first.

I could not get it to work with your example files either. so, must be Windows related.

pgfearo commented 3 years ago

Ok, I've dusted off my Windows laptop and I can reproduce the issue immediately with even simple expressions like:

  'hello world'

This is definitely a windows file path issue. Node.js is not expecting '\' chars without escaping I think. There's a bit of complexity here because JavaScript is being created dynamically to load the compiled XSLT.

pgfearo commented 3 years ago

@RandomFractals The error you were getting was specific to Windows and has now been fixed in v0.0.3. I added a new issue: issue #4

RandomFractals commented 3 years ago

this looks much better now. Thanks for that patch!

image