Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add XPath Notebook Samples #2

Open
2 tasks
pgfearo opened this issue Jul 29, 2021 · 10 comments
Open
2 tasks

Add XPath Notebook Samples #2

pgfearo opened this issue Jul 29, 2021 · 10 comments
Labels
enhancement New feature or request

Comments

@pgfearo
Copy link
Member

pgfearo commented Jul 29, 2021

  • Basic Tutorial
  • Data Science Tutorial - tables etc.
@pgfearo pgfearo added the enhancement New feature or request label Jul 29, 2021
@RandomFractals
Copy link

RandomFractals commented Jul 29, 2021

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
Copy link

I might use that dataset for providing XPath notebook example in my data table renderer extension here: RandomFractals/vscode-data-table#69

@RandomFractals
Copy link

@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
Copy link
Member Author

pgfearo commented Jul 30, 2021

@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
Copy link

@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
Copy link
Member Author

pgfearo commented Jul 31, 2021

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
Copy link

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
Copy link
Member Author

pgfearo commented Jul 31, 2021

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
Copy link
Member Author

pgfearo commented Jul 31, 2021

@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
Copy link

RandomFractals commented Jul 31, 2021

this looks much better now. Thanks for that patch!

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants