i582 / vxml

Pure V library for parsing XML to a DOM.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

vxml

Pure V library for parsing XML. The data is accessed with a tree API accessible directly within the Node struct.

This library is now alive.

Install.

v install walkingdevel.vxml

Usage.

fn parse(xml string) Node
fn parse_file(path string) !Node

struct Node {
pub mut:
        attributes map[string]string
        name       string
        text       string
        cdata      string
        children   []&Node
        parent     &Node
}

fn (node Node) is_root() bool
fn (node Node) get_elements_by_tag_name(name string) []&Node
fn (node Node) get_element_by_tag_name(name string) !&Node
fn (node Node) get_elements_by_predicate(predicate fn (&Node) bool) []&Node
fn (node Node) get_attribute(name string) !string
fn (node Node) get_text() string
fn (node Node) get_cdata() string

Example.

import vxml { parse_file }

fn main() {
  news := parse_file('./news.xml') or { panic(err) }

  posts := news.get_elements_by_tag_name('post')

  println(posts.first().get_text())
}

It doesn't support (yet):

  • Error handling
  • Schemas (DTD)

The features listed above will all be supported soon.

About

Pure V library for parsing XML to a DOM.

License:MIT License


Languages

Language:V 90.2%Language:HTML 7.7%Language:AMPL 2.1%