Class: Teius::Document

Inherits:
Node
  • Object
show all
Defined in:
lib/teius.rb,
ext/teius.c

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#==, #[], #attributes, #children, #document, #eql?, #fetch, #find, #hash, #line, #name, #parent, #pointer, #siblings, #type, #value, #xpath

Class Method Details

.content(xml) ⇒ Object



9
10
11
# File 'lib/teius.rb', line 9

def self.content(xml)
  parse_string(xml).content
end

.parse_file(rFilename) ⇒ Object



233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'ext/teius.c', line 233

static VALUE document_parse_file(VALUE self, VALUE rFilename) {
  xmlDocPtr doc = xmlReadFile(StringValuePtr(rFilename), NULL, 0);
  if (doc == NULL) {
    xmlErrorPtr  err = xmlGetLastError();
    rb_raise(cParseError, "could not parse file %s: %s", 
      StringValuePtr(rFilename), err->message);
  }

  /* Load new document */
  VALUE rDoc = Data_Wrap_Struct(self, 0, doc_free, doc);

  return rDoc;
}

.parse_string(rDocString) ⇒ Object



247
248
249
250
251
252
253
254
255
256
257
258
# File 'ext/teius.c', line 247

static VALUE document_parse_string(VALUE self, VALUE rDocString) {
  xmlDocPtr doc = xmlReadDoc((xmlChar *)StringValuePtr(rDocString), NULL, NULL, 0);
  if (doc == NULL) {
    xmlErrorPtr  err = xmlGetLastError();
    rb_raise(cParseError, "could not parse string: %s", err->message);
  }

  /* Load new document */
  VALUE rDoc = Data_Wrap_Struct(self, 0, doc_free, doc);

  return rDoc;
}

Instance Method Details

#contentObject



13
14
15
# File 'lib/teius.rb', line 13

def content
  root.content
end

#rootObject



273
274
275
276
277
278
279
280
281
282
283
# File 'ext/teius.c', line 273

static VALUE document_root(VALUE self) {
  xmlDocPtr  doc = NULL;
  xmlNodePtr node = NULL;
  VALUE rResult;
  
  Data_Get_Struct(self, xmlDoc, doc);
  node = xmlDocGetRootElement(doc);
  rResult = Data_Wrap_Struct(cNode, 0, 0, node);
  
  return rResult;
}

#to_sObject



260
261
262
263
264
265
266
267
268
269
270
271
# File 'ext/teius.c', line 260

static VALUE document_to_s(VALUE self) {
  xmlDocPtr  doc = NULL;
  xmlChar *mem;
  int size;
  
  Data_Get_Struct(self, xmlDoc, doc);
  xmlDocDumpMemory(doc, &mem, &size);
  VALUE rStr = rb_str_new2((char *)mem);
  xmlFree(mem);
  
  return rStr;
}