File: writeParsedDoc.rb

package info (click to toggle)
nqxml 1.1.3p1-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 412 kB
  • ctags: 331
  • sloc: ruby: 3,177; makefile: 89; xml: 41
file content (33 lines) | stat: -rwxr-xr-x 1,211 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#! /usr/bin/env ruby
#
# Copyright (c) 2001 by Jim Menard <jimm@io.com>
#
# Released under the same license as Ruby. See
# http://www.ruby-lang.org/en/LICENSE.txt.
#
# This script creates an XML file by parsing an XML file with a tree parser
# and passing the resulting document object to a writer.
#

# Start looking for NQXML classes in the directory above this one.
# This forces us to use the local copy of NQXML, even if there is
# a previously installed version out there somewhere.
$LOAD_PATH[0, 0] = '..'

require 'nqxml/treeparser'
require 'nqxml/writer'

# Open a file, create a tree parser and give it the file, and retrieve
# the parsed document. Gee, this comment is longer than the code.
doc = NQXML::TreeParser.new(File.open('doc.xml')).document

# Create a writer and point it to stdout. We don't have to use the
# newline-inserting "prettify" argument here since the document
# itself contains newlines that will be output by the writer.
writer = NQXML::Writer.new($stdout)
writer.writeDocument(doc)

# The last newline, since it is outside the root entity of the document
# and is purely whitespace, is ignored by the NQXML::TreeParser. Let's
# add a newline to our output.
writer.write("\n")