西藏巴青项目

parse-gis-api-doc.mjs 961B

12345678910111213141516171819202122232425262728293031323334353637
  1. import fs from 'fs'
  2. import os from 'os'
  3. import path from 'path'
  4. const xmlPath = path.join(os.tmpdir(), 'gis-doc-raw.xml')
  5. const x = fs.readFileSync(xmlPath, 'utf8')
  6. function strip(chunk) {
  7. return chunk
  8. .replace(/&lt;/g, '<')
  9. .replace(/&gt;/g, '>')
  10. .replace(/&quot;/g, '"')
  11. .replace(/&amp;/g, '&')
  12. .replace(/<w:tab[^>]*\/>/g, '\t')
  13. .replace(/<\/w:p>/g, '\n')
  14. .replace(/<[^>]+>/g, '')
  15. .replace(/\n{3,}/g, '\n\n')
  16. }
  17. const text = strip(x)
  18. const keys = ['周边', '2.2', 'longitude', 'latitude', 'radius', 'page_size', 'pageSize', 'POI', '搜索', 'nearby', 'agis']
  19. for (const k of keys) {
  20. const i = text.indexOf(k)
  21. if (i >= 0) {
  22. console.log(`\n######## ${k} @ ${i} ########`)
  23. console.log(text.slice(Math.max(0, i - 150), i + 1200))
  24. }
  25. }
  26. // dump section around "2.2"
  27. const i22 = text.indexOf('2.2')
  28. if (i22 >= 0) {
  29. console.log('\n######## FULL 2.2 SECTION ########')
  30. console.log(text.slice(i22, i22 + 4000))
  31. }