G
G
gto61202016-12-25 15:04:08
cmd/bat
gto6120, 2016-12-25 15:04:08

Bat how to generate xml?

Font search works very poorly in nexus font, it cannot find it recursively, even if you set the appropriate directory in the configuration file, so you need to generate xml like:

<?xml version="1.0" encoding="UTF-8"?>
<library>
  <groups>
    <group name="fonts" expanded="true">
      <folder>H:\fonts\Akrobat</folder>
      <folder>H:\fonts\Amsdam Regular</folder>
      <folder>H:\fonts\Arkhip</folder>
    </group>
  </groups>
  <sets>
    <set name="готичесие"/>
    <set name="рисованные"/>
  </sets>
</library>

Actually, you need to change the group section as new fonts are added to the collection (they are in the H:\fonts\ folder). I want to make a batch file for this purpose. It is very difficult to understand this over-sophisticated underlanguage. So far, I could only write something approximately similar to a file. Here is the script:
@echo off
for /f %%a in ('dir /b /a:d /o:n "H:\fonts\*"') do (
echo "<folder>H:\fonts\%%a</folder>" >> library.xml
)
pause

The script writes this:
"<folder>H:\fonts\Akrobat</folder>" 
"<folder>H:\fonts\Amsdam</folder>" 
"<folder>H:\fonts\Anchor</folder>" 
...

Problem #1 : There shouldn't be quotes around folder tags, and writing without them doesn't work at all.
Problem #2 : spaces in the font name cause only the first word of the name to be taken, and the names must be with spaces. As a result, you can see that Amsdam Regular has become just Amsdam.
Problem #3 : I generate only the section that I need (group), but I don’t know how to enter it in the right place, replacing the previous value.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
res2001, 2016-12-25
@gto6120

Problem #1: If you remove the quotes, the < > characters will cause errors because these are service symbols in batch files - redirect symbols. Try escaping them: ^> ^<
Try it, it might work with escaping. In general, in batch files there is a problem with shielding, sometimes unsolvable. Several times I came across the fact that it was easier to write a script, for example in javascript, due to a problem with escaping service characters.
But you have a simple option, it should work. I can't check myself right now.
Problem #2: Make your loop look like this:
for /f "tokens=* delims=" %%a in ('dir /b /a:d /o:n "H:\fonts\*"')
Problem #3: I would suggest that you make 2 blanks for the resulting xml - the part before the insertion (header) and the part after the insertion. After forming the insert, simply fold 3 parts like this:
copy header.xml+insert.xml+footer.xml library.xml
Or generate the rest of the xml with a batch file.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question