Find in Files iwth XPath
Oxygen general issues.
-
- Posts: 97
- Joined: Tue Apr 22, 2008 9:31 am
Find in Files iwth XPath
Hi
I have a number of XML files that I want to search to find examples of files that contain five or more elements named 'accountNumber' in the one file.
How can I use the 'Restrict to XPath' field in the 'Find/Replace in Files' dialog for this type of search. I have lots and lots of files with one or two elements 'accountNumber'.
I had thought to use an XPath expression such as: but I could not get it to work. I have tried this and variations.
What would you suggest?
I have a number of XML files that I want to search to find examples of files that contain five or more elements named 'accountNumber' in the one file.
How can I use the 'Restrict to XPath' field in the 'Find/Replace in Files' dialog for this type of search. I have lots and lots of files with one or two elements 'accountNumber'.
I had thought to use an XPath expression such as:
Code: Select all
count(//accountNumber) > 5
What would you suggest?
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: Find in Files iwth XPath
Hello,
First I would like to ask you to update Oxygen to the latest build(2010020412) which includes a few fixes regarding Find/Replace in Files. You can find it here:
http://www.oxygenxml.com/download_oxygenxml_editor.html
The XPath is used for determining the intervals to be searched from a document, so the XPath result has to be a node-set.
What you want can be done with:
Please note that this will only search inside the root of the selected documents(that have more than 5 accountNumber elements).
And you will also have to use a Text to find to actually search for some text. accountNumber would be appropriate in your case.
Let me know if you need further help.
Regards,
Adrian
First I would like to ask you to update Oxygen to the latest build(2010020412) which includes a few fixes regarding Find/Replace in Files. You can find it here:
http://www.oxygenxml.com/download_oxygenxml_editor.html
The XPath is used for determining the intervals to be searched from a document, so the XPath result has to be a node-set.
What you want can be done with:
Code: Select all
/*[count(//accountNumber) > 5]
And you will also have to use a Text to find to actually search for some text. accountNumber would be appropriate in your case.
Let me know if you need further help.
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
-
- Posts: 45
- Joined: Mon Aug 24, 2009 11:42 pm
Re: Find in Files with XPath
I'm having trouble with this function. I want to find instances of a particular element without regard to its contents. My XPath expression is: //div[@type='addendum']. I have verified that the Scope setting is correct.
If I put the XPath expression in the "Text to Find" field, I get back zero results, when I should get hundreds of hits. If I put the XPath expression in the "Restrict to XPath" field with an empty string in "Text to Find", Oxygen complains that I "Cannot search for a blank string", which makes sense, of course. If I put .* in the "Text to Find" and check the Regular Expression checkbox, I get back too many hits (one hit for each line within the <div>)> I only want one hit for each instance of the <div> element.
I am stumped. How do I find all instances of a particular element in all files in a project where the contents of the element is irrelevant?
I am running Oxygen 12.2 (build 2011062910) on Windows 7.
Thank you.
If I put the XPath expression in the "Text to Find" field, I get back zero results, when I should get hundreds of hits. If I put the XPath expression in the "Restrict to XPath" field with an empty string in "Text to Find", Oxygen complains that I "Cannot search for a blank string", which makes sense, of course. If I put .* in the "Text to Find" and check the Regular Expression checkbox, I get back too many hits (one hit for each line within the <div>)> I only want one hit for each instance of the <div> element.
I am stumped. How do I find all instances of a particular element in all files in a project where the contents of the element is irrelevant?
I am running Oxygen 12.2 (build 2011062910) on Windows 7.
Thank you.
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: Find in Files iwth XPath
Hello,
The XPath expression can only be used in the Restrict to XPath field, but you still have to search for something(in the Text to find field), the XPath only functions as a filter.
Note that the Find/Replace in Files works different than the Find/Replace in an editor. Find/Replace in Files searches one line at a time, so if the XPath result is on multiple lines, you will obtain multiple matches, one for each line.
If all you want is the location(start) or the number of occurrences of the element, you can search for <div (in the Text to find field) and use the mentioned XPath expression(in the Restrict to XPath field).
Let me know if you encounter further difficulties.
Regards,
Adrian
The XPath expression can only be used in the Restrict to XPath field, but you still have to search for something(in the Text to find field), the XPath only functions as a filter.
Note that the Find/Replace in Files works different than the Find/Replace in an editor. Find/Replace in Files searches one line at a time, so if the XPath result is on multiple lines, you will obtain multiple matches, one for each line.
If all you want is the location(start) or the number of occurrences of the element, you can search for <div (in the Text to find field) and use the mentioned XPath expression(in the Restrict to XPath field).
Let me know if you encounter further difficulties.
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: Find in Files iwth XPath
Hi,
Find/Replace in Files is meant to search for content in files (hence the name), so you have to define a string or expression that you want to find inside the files (positive find).
You could use directly the XPath toolbar (or the XPath/XQuery Builder, Window > Show View >...) and write an XPath (2.0) that does this instead.
e.g. This obtains a list of all XML files (their root elements actually) that do not have "element" elements.
You can also make use of the current file directory (of the editor selected in Oxygen) instead of specifying the full folder URL.
e.g.
Regards,
Adrian
I'm afraid you can't, at least not by using negative find logic.sarcanon wrote:More on this topic. How would I find files NOT containing a certain XPath expression?
Find/Replace in Files is meant to search for content in files (hence the name), so you have to define a string or expression that you want to find inside the files (positive find).
You could use directly the XPath toolbar (or the XPath/XQuery Builder, Window > Show View >...) and write an XPath (2.0) that does this instead.
e.g.
Code: Select all
collection('file:/C:/path/to/folder/?select=*.xml')/*[not(//element)]
You can also make use of the current file directory (of the editor selected in Oxygen) instead of specifying the full folder URL.
e.g.
Code: Select all
collection('.?select=*.xml')/*[not(//element)]
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service