XPath Module not working (No Output, Scenario stops)

I fetch a website’s sitemap (XML) and use a XML/Perform XPath Query module to get the URLs listed in the sitemap.

Sounds quite easy but whatever I enter into the “XPath Query” field in that module, no output is generated. Except if I enter //* then all elements are outputted.

I have not found any info on the usage of this module anywhere online.

I have also tried things like: //loc/text()

The structure of one entry in the sitemap XML is this:

	<url>
		<loc>https://mylittlewebsite.com/en/open-source/</loc>
		<lastmod>2023-06-05T05:46:26+00:00</lastmod>
		<image:image>
			<image:loc>https://mylittlewebsite.com/wp-content/uploads/2023/06/image-29.jpg</image:loc>
		</image:image>
	</url>

You don’t need an XPath module for this.

You can use a Text Parser “Match Pattern” module with this Pattern (regular expression):

<loc>\s*(?<url>.+?)\s*<\/loc>

Proof https://regex101.com/r/ZHIJl9/1

Important Info

  • :warning: Global match must be set to YES!

For more information, see Text Parser in the Make Help Center:

Match Pattern
The Match pattern module enables you to find and extract string elements matching a search pattern from a given text. The search pattern is a regular expression (aka regex or regexp), which is a sequence of characters in which each character is either a metacharacter, having a special meaning, or a regular character that has a literal meaning.

Module Export - quick import into your scenario

You can copy and paste this module export into your scenario. This will import the modules (with fields/settings/filters) shown in my screenshots above.

  1. Move your mouse over the line of code below. Copy the JSON by clicking the copy button on the right of the code, which looks like this:

  2. Enter your scenario editor. Press ESC to close any dialogs. Press CTRLV (paste keyboard shortcut for Windows) to paste directly in the editor.

  3. Click on each imported module and re-save it for validation. There may be some errors prompting you to remap some variables and connections.

JSON module export — paste this directly in your scenario

{"subflows":[{"flow":[{"id":276,"module":"regexp:Parser","version":1,"parameters":{"pattern":"<loc>\\s*(?<url>.+?)\\s*<\\/loc>","global":true,"sensitive":false,"multiline":false,"singleline":false,"continueWhenNoRes":false,"ignoreInfiniteLoopsWhenGlobal":false},"mapper":{"text":"{{toString(274.data)}}"},"metadata":{"designer":{"x":1702,"y":-2236,"messages":[{"category":"last","severity":"warning","message":"A transformer should not be the last module in the route."}]},"parameters":[{"name":"pattern","type":"text","label":"Pattern","required":true},{"name":"global","type":"boolean","label":"Global match","required":true},{"name":"sensitive","type":"boolean","label":"Case sensitive","required":true},{"name":"multiline","type":"boolean","label":"Multiline","required":true},{"name":"singleline","type":"boolean","label":"Singleline","required":true},{"name":"continueWhenNoRes","type":"boolean","label":"Continue the execution of the route even if the module finds no matches","required":true},{"name":"ignoreInfiniteLoopsWhenGlobal","type":"boolean","label":"Ignore errors when there is an infinite search loop","required":true}]}}]}],"metadata":{"version":1}}

Note: Did you know you can reduce the size of blueprints and module export code like the above, using the Make Blueprint Scrubber?

Hope this helps! Let me know if there are any further questions or issues.

@samliew

P.S.: Investing some effort into the Make Academy will save you lots of time and frustration using Make.

2 Likes

Thanks a lot - it works like this (and I also just learnt that you can paste a module’s json - very cool!

Still an odd feeling as to why it didn’t work with XPath - would be interesting to know what I was doing wrong :slight_smile:

2 Likes