0

As a follow-up to this question, I now have the following command:

set +H && java -cp saxon-he-10.5.jar net.sf.saxon.Query -config:saxon.xml -s:rss.xml -qs:'//item/link!substring-after(., "_")' 

saxon.xml

<?xml version="1.0"?> <!-- For documentation on the contents of a Saxon configuration file, see http://www.saxonica.com/html/documentation/configuration/configuration-file/index.html --> <configuration edition="HE" xmlns="http://saxon.sf.net/ns/configuration" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://saxon.sf.net/ns/configuration config.xsd"> <global optimizationLevel="10" stripSpace="ignorable" recoveryPolicy="doNotRecover" dtdValidationRecoverable="no" /> </configuration> 

How can this be tweaked to get my desired output?

Desired Output

92.204.241.167 181.24.239.244 193.243.195.66 

Present Output

<?xml version="1.0" encoding="UTF-8"?>92.204.241.167 181.24.239.244 193.243.195.66 

1 Answer 1

2

You can specify serialization properties either on the command line, or as part of the query itself, or in the configuration file. On the command line, use for example

!indent=yes 

remembering that with some shells the ! needs to be escaped as \!.

Within the query, use for example declare option output:indent "yes";.

In the configuration file, specify <serialization indent="yes"/>

The serialization parameters that you could consider here include:

  • method=text - suppresses the XML declaration and prevents escaping of special characters such as &.

  • omit-xml-declaration=yes - suppresses the XML declaration but does not prevent escaping

  • item-separator=\n - uses a newline rather than a single space as the separator between items. The problem here is how to represent the newline. With the shell, \n is the most likely candidate, but it will probably need to be in quotes and it might vary from one shell to another. Within the query, or within the configuration file it will need to be written as &#xa;.

Finally, as an alternative to using the item-separator serialization property, you could introduce the newlines as part of the query itself, by writing it as

(//item/link!substring-after(., "_")) => string-join("&#xa;") 
2
  • Thanks for your help! After running these I noticed a final newline isn't appended. Is there a way to do so? Commented Jul 5, 2021 at 22:07
  • If you want a newline after every item including the last, try (//item/link!(substring-after(., "_")||"&#xa;") Commented Jul 6, 2021 at 23:06

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.