Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to extract an XPATH with the command-line BaseX parser?

Posted on 2013-06-08
11
Medium Priority
?
746 Views
Last Modified: 2013-06-12
I would to extract an XPATH defined part of html from an html file on my local disk using BaseX command line XML parser.
I found a very short documentation page here: http://docs.basex.org/wiki/Standalone_Mode

I tried but I'm lost...

What's the command-line syntax for doing this?
0
Comment
Question by:lucavilla
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 27

Expert Comment

by:skullnobrains
ID: 39232163
i know it is not your question but given one of your other open threads, maybe this will be a goos starting point

http://www.semicomplete.com/projects/xpathtool/

read the inline doc, basically run something like this

./xpathtool.sh --pretty --indent '//element' << yourfile.xml
0
 

Author Comment

by:lucavilla
ID: 39232171
is it for Windows command-line?  I need it working in Windows (7)
0
 
LVL 27

Expert Comment

by:skullnobrains
ID: 39232271
no, but it should run fine in cygwin

xsltproc itself is available both for windows and through cygwin

it should be fairly easy to setup a .xslt file that performs an xpath query if you want to do it in windows

something like this should do. change the expression as required and use this as the xslt file to feed xsltproc. you can easily write a batch file that does that for you once you worked it out manually

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >

<xsl:template match="/">
    <xsl:copy-of select="YOUR XPATH EXPRESSION"/>
</xsl:template>

</xsl:stylesheet>

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:lucavilla
ID: 39232284
hmmm I would like something simpler, something that I can launch like this:

XPATHparser.exe input.html "//div[@id='myid']" > output.html
0
 
LVL 27

Expert Comment

by:skullnobrains
ID: 39232309
yes

either use xpathtool through cygwin (install cygwin, and xsltproc package, and copy the xpathtool script to your system)

OR

stick the above xslt in a batch file that does what you need.

first figure out how to run xsltproc manually with the file, then you'll be able to create the batch file. i'll help along the way
0
 

Author Comment

by:lucavilla
ID: 39232322
batch files or script files is not what I want.... I need a faster all-in-command-line solution...
0
 
LVL 27

Expert Comment

by:skullnobrains
ID: 39232336
is copy-paste 9 lines of code into a file, name it XPATHparser.bat, add and xpath comand in order to build your tool too much of a hassle ?

is installing a software too much ?

i'd be glad to help you if you at least give a try to either of the above suggestions. if not i can help you find a graphical tool that does that (jedit with the xml plugin for example)

some basic googling (xpath command line windows) also point here
http://xmlstar.sourceforge.net/docs.php
apparently the "sel" option will let you perform an xpath query
something like "xml sel //node <<input.xml > output.xml" should do
windows binaries are available in the download section
0
 

Author Comment

by:lucavilla
ID: 39232898
I need for a command-line solution because I need to add XPATH filtering ability in a commercial program (Website Watcher) that supports a simple scripting language where it can (at best, for this purpose) write a variable (eg. the html of a my given webpage) to a file, execute a command-line, read a file (eg. my wanted XPATH reduced page) to a variable... and continue with other processing over that variable...
I need to launch it from many different scripts and with many different XPATHs and having to write (and remember) lines of code every time I've to use it is not my best solution in my opinion.

This commercial program also supports regular expressions and indeed I always did the html filtering by well-refined regular expressions in a single line of code but now a crowd of developers tell me that XPATH is better... and simpler...
0
 
LVL 27

Accepted Solution

by:
skullnobrains earned 1500 total points
ID: 39234299
nobody asked you to remember a bunch of commands.

btw, batches and sh scripts ARE command-line tool that let you do a bunch of things including store commands so you do not have to remember them and retype them every time

try and understand the solutions that are given to you. actually try them. don't expect me to install and configure the tool on your computer. if that is what you want, better hire a guy than ask on a forum.

also note that you'd have had much better help by giving this iformation in the first place

---

i gave you
- a way to build a batch command line tool that does what you want
- a command line tool that can be installed on cygwin that does exactly what you require
- a command line tool (xmlstar) that does exactly what you require

there is nothing more a can do to help you unless you at least give a try to something.
xmlstar looks like the easiest : comes with an msi installer and good documentation.
0
 

Author Closing Comment

by:lucavilla
ID: 39239676
...
0
 
LVL 27

Expert Comment

by:skullnobrains
ID: 39240362
feel free to post if you do try something and need help
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.NET AJAX callbacks to web service are becoming very popular and unavoidable these days. The feel that the user gets when only a part of the page is updated without even hindering the UI is the advantage that the callbacks offer. The wait for the…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question