Thread: Validating XML in ANSI C...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Location
    I live in a small town in germany near Dusseldorf
    Posts
    2

    Validating XML in ANSI C...

    Hi there!

    First I have to say, that reading this Forum was a real joy for me! Quite a few things to learn and a rather kind of communication. I like that pretty much!

    Now to my question:

    I'm writing a program that needs to post commands to a server. These commands are designed in a special flavour of XML.
    All this works pretty nice.
    Now I would like to validate my commands BEFORE I send them to the server. Checking if it is wellformed should be rather simple. But the problem is the logical validation. Imagine a simple example:

    Example 1: A simple wellformed XML-command (simplified)

    Code:
    <root>
       <command>
          <createsomething>
              <parameter1>value1</parameter1>
              <parameter2>value2</parameter2>
          </createsomething>
       </command>
    <root>
    This command would be valid XML. But it might NOT be a valid command. For example there might be a parameter3 required. Or the values would need to be in a special charset or whatever. All these requirements are defined in a XML-Scheme.

    So what I need to do:
    - read the scheme
    - analyze it
    - validate the XML using it

    I guess, the real tough part will be, analyzing it.. Imagine the scheme contains something like "if". How can I create some kind of code, that changes, depending on input (the scheme)??

    I can't imagine, how to do this and need your help...

    BTW: I can't use libxml2 or any other "extra library" that I would have to install.. And the target system is a old linuxbox. *sigh*

    Thanks in advance!

    frozen

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > BTW: I can't use libxml2 or any other "extra library" that I would have to install
    I'd say porting something which already exists, and trying to write and debug your own code are about the same.

    "Libxml2 is known to be very portable"
    Actually, I'd favour the porting option right now.

    Or maybe use a perl module
    http://search.cpan.org/~grantm/XML-S.../XML/Simple.pm
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Mar 2006
    Location
    I live in a small town in germany near Dusseldorf
    Posts
    2
    Quote Originally Posted by Salem
    I'd say porting something which already exists, and trying to write and debug your own code are about the same.

    "Libxml2 is known to be very portable"
    Actually, I'd favour the porting option right now.
    Hello Salem,

    thank you very much for your answer!

    I looked at the perl module you linked to and found out, that it doesn't allow any kind of schema-based validation.
    I had a closer look at libxml2 and found out, that the schema-validation is in a very early state. They say:
    A partial implementation of XML Schemas Part 1: Structure is being worked on but it would be far too early to make any conformance statement about it at the moment.
    I'm afraid, this won't be perfect. Since I would have to use the xml-parser from libxml2 to be able to use the existing parts of schema-validation implemented in libxml2, this would be rather senseless for me, since I developed my own (small and not-so-perfect-but-working) xml-parser. My parser is rather special and works really great for MY project, while the libxml2-parser(s) try to be usable for nearly all data, that is some kind of XML. So these parsers implement a lot of things I will never use - they are oversized...

    Validation of the XML-commands is not absolutely necessary for my project. But I would really love to make it possible.. ;-) I'm somehow afraid, that the things not being implemented in libxml2 are the things, I would like best.. ;-) I will have a closer look at it, maybe this code gives me some ideas.

    Thanks again,

    frozen

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Parsing Xml
    By deviousdexter in forum C# Programming
    Replies: 7
    Last Post: 04-24-2009, 06:29 AM
  2. Dissecting an Excel XML spreadsheet
    By desmond5 in forum C++ Programming
    Replies: 1
    Last Post: 05-22-2008, 04:32 PM
  3. XML encoding issue
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 05-16-2008, 05:21 AM
  4. XML and data exchange
    By seexml in forum C Programming
    Replies: 0
    Last Post: 04-27-2006, 03:02 PM
  5. sigaction() and ANSI C
    By awoodland in forum Linux Programming
    Replies: 4
    Last Post: 04-25-2004, 01:48 AM