30-10-07

Parsing HTML in C by use of LibXML2

When you compile this project don't forget to include the libxml2.dll in the map where you compile or to add it to your project!

 

It shows the tags their are in for instance an HTML file and the contents of it.. Please be aware that for instance when I show you the HTML tag he puts the whole content of the site in your standard output (console).

 

/**
 * section: Tree
 * synopsis: Navigates a tree to print element names
 * purpose: Parse a file to a tree, use xmlDocGetRootElement() to
 *          get the root element, then walk the document and print
 *          all the element name in document order.
 * usage: tree1 filename_or_URL
 * test: tree1 test2.xml > tree1.tmp ; diff tree1.tmp tree1.res ; rm tree1.tmp
 * author: Dodji Seketeli
 * copy: see Copyright for the status of this software.
 */
#include <stdio.h>
#include <libxml/parser.h>
#include <libxml/tree.h>

#ifdef LIBXML_TREE_ENABLED

/*
 *To compile this file using gcc you can type
 *gcc `xml2-config --cflags --libs` -o xmlexample libxml2-example.c
 */

/**
 * print_element_names:
 * @a_node: the initial xml node to consider.
 *
 * Prints the names of the all the xml elements
 * that are siblings or children of a given xml node.
 */
static void print_element_names(xmlNode * a_node)
{
    xmlNode *cur_node = NULL;
    xmlChar *fieldContent;

    for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
       if (cur_node->type == XML_ELEMENT_NODE) {
                          fieldContent=xmlNodeGetContent(cur_node);
        printf("Tagname: %s ttTagcontent: %sn", cur_node->name,fieldContent);
       }
        print_element_names(cur_node->children);
    }
}


/**
 * Simple example to parse a file called "file.xml",
 * walk down the DOM, and print the name of the
 * xml elements nodes.
 */
int main(int argc, char **argv)
{
    xmlDoc *doc = NULL;
    xmlNode *root_element = NULL;

    if (argc != 2)
        return(1);

    /*
     * this initialize the library and check potential ABI mismatches
     * between the version it was compiled for and the actual shared
     * library used.
     */
    LIBXML_TEST_VERSION

    /*parse the file and get the DOM */
    doc = xmlReadFile(argv[1], NULL, 0);

    if (doc == NULL) {
        printf("error: could not parse file %sn", argv[1]);
    }

    /*Get the root element node */
    root_element = xmlDocGetRootElement(doc);

    print_element_names(root_element);

    /*free the document */
    xmlFreeDoc(doc);

    /*
     *Free the global variables that may
     *have been allocated by the parser.
     */
    xmlCleanupParser();

    return 0;
}
#else
int main(void) {
    fprintf(stderr, "Tree support not compiled inn");
    exit(1);
}
#endif

16:50 Gepost door Mobile blogger in Algemeen | Permalink | Commentaren (0) | Tags: xml, parsing, html, c, libxml2, dll, parser, parsing |  Facebook |

26-04-07

2 blinking leds on my ATtiny2313 board

I have made an example of an blinking led (programmed in C) for getting someone started for a robot project.

 

I used PonyProg2000 for download the hex file to the ATTINY2313 Microcontroller and used CodeVisionAVR (evaluation version) as an IDE for the C programming.

 

Here is the code (you can consider this as an Hello world for the ATTINY2313 :

 

#include <tiny2313.h> 
#include <delay.h>

// Declare your global variables here

void main(void)
{
// Declare your local variables here

// Crystal Oscillator division factor: 1
#pragma optsize-
CLKPR=0x80;
CLKPR=0x00;
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif

// Input/Output Ports initialization
// Port A initialization
// Func2=In Func1=In Func0=In
// State2=T State1=T State0=T
PORTA=0x00;
DDRA=0x00;

// Port B initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0
PORTB=0x00;
DDRB=0xFF;

// Port D initialization
// Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0A output: Disconnected
// OC0B output: Disconnected
TCCR0A=0x00;
TCCR0B=0x00;
TCNT0=0x00;
OCR0A=0x00;
OCR0B=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// Interrupt on any change on pins PCINT0-7: Off
GIMSK=0x00;
MCUCR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;

// Universal Serial Interface initialization
// Mode: Disabled
// Clock source: Register & Counter=no clk.
// USI Counter Overflow Interrupt: Off
USICR=0x00;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;

while (1)
      {
      // Place your code here
                PORTB=0x01;
                delay_ms(50);
                PORTB=0x02 ;
                delay_ms(50);


      };
}

04-02-07

Working with Google Codesearch

Hi all,

 

ready for some geek google stuff?

 

there is a searchengine called 'Google Code Search' where you as a  developer in the electronic world can get many help from ( or ideas ) Here a few examples:

 

go to this website: http://www.google.com/codesearch

type: SPI lang:vhdl

quicklink: http://www.google.com/codesearch?q=SPI+lang%3Avhdl&hl...

 

and there you go, the VHDL code for an SPI interface.

 

Whatch the following example: Hello world for C++:

http://www.google.com/codesearch?hl=nl&lr=&q=hell...

 

enjoy this feature of google!

12:24 Gepost door Mobile blogger in Algemeen | Permalink | Commentaren (0) | Tags: google, c, vhdl, codesearch, spi interface |  Facebook |

22-11-06

Importing Assembler code into a C application

Here you find an example of implementing assembler code into a C application that you can build with your Visual C++ compiler... When you put 'Inline Assembler' in the magic google box you get more information about this topic. I have only tested this on Visual Studio 2005, not on GCC or other compilers, you can best check your compiler for how to implement assembler code into your C program.

Have fun...

 

#include <stdio.h>
 
main() {
 
    int arg1=3;
     int arg2=4;
     int Result;
 
_asm{
MOV arg1,202
MOV arg2,125
MOV EAX,arg1
MOV EBX,arg2
ADD EAX,EBX
MOV Result,EAX
}
   printf("%dt%dt%d",arg1,arg2,Result);
}

18:42 Gepost door Mobile blogger in Algemeen | Permalink | Commentaren (0) | Tags: assembler, ansi, c, inline, gcc, visual studio 2005, download, example |  Facebook |