XML instance generation from XML schema (xsd)

108

Solution 1

Look at pyXSD for Python tools that are similar to JAXB.

XSD's are used to create Python classes. Python objects are used to emit XML.

Solution 2

Microsoft has published a "document generator" tool as a sample. This is an article that describes the architecture and operation of the sample app in some detail.

If you just want to use the document generation tool, click here and install the MSI. It requires no programming.

It's free. The source is available. Requires the .NET Framework to run. Works only with XSDs. (not Relax NG or DTD).

Solution 3

I recommend two approaches:

  1. Xstream - it let's you generate XML files by defining a Java file and either putting Java annotations on the items or just defining aliases. It is very easy, but it is not fully automatic;

  2. XMLBeans - these tools let's you generate Java files from XML schema definitions (xsd) so that you can import, manipulate, create and export XML files using JavaBeans-like method calls.

Regards, Luis

Solution 4

JAXB works fantastic for generating classes from xsd.

Ibatis works fantastic for getting data into classes.

You can use Ibatis to feed data and automatically create classes, then use JAXB to marshal the classes into an XML file! Mind you, that's a lot of effort if you're not going to be doing it over and over again.

Share:
108
Gail Hartle
Author by

Gail Hartle

Updated on July 09, 2022

Comments

  • Gail Hartle
    Gail Hartle almost 2 years

    This seems like it should be simple, but I've tried it every which way and can't seem to get it to work.

    I have this login script which I adapted from an online tutorial. What I'd like to do is have users sign in with a username and password, and if these are correct, have it go after their lab results in another table (same database) and display them. I can get it to sign in, but that's it. Here's the login code:

    <?php  //Start the Session
    session_start();
     require('connect.php');
    //3. If the form is submitted or not.
    //3.1 If the form is submitted
    if (isset($_POST['username']) and isset($_POST['password'])){
    //3.1.1 Assigning posted values to variables.
    $username = $_POST['username'];
    $password = $_POST['password'];
    //3.1.2 Checking the values are existing in the database or not
    $query = "SELECT * FROM `user` WHERE username='$username' and password='$password'";
    
    $result = mysql_query($query) or die(mysql_error());
    $count = mysql_num_rows($result);
    //3.1.2 If the posted values are equal to the database values, then session will be created for the user.
    if ($count == 1){
    $_SESSION['username'] = $username;
    }else{
    //3.1.3 If the login credentials doesn't match, he will be shown with an error message.
    echo "Invalid Login Credentials.";
    }
    }
    //3.1.4 if the user is logged in Greets the user with message
    if (isset($_SESSION['username'])){
    $username = $_SESSION['username'];
    echo "Hi " . $username . "! ";
    echo "This is the results of your inquiry.<br><br>";
    
    
    
    
    /*This is where I'm assuming the new query needs to go.
    Query a different table named "data"  and pick out information according to 
    $username which was put in earlier */
    
    
    
    
    echo "<br><a href='logout.php'>Logout</a>";
    
    }else{
    //3.2 When the user visits the page first time, simple login form will be displayed.
    ?>
    <!DOCTYPE html>
    
    <html>
    <head>
      <title>Lab Sign In Page</title>
      <link rel="stylesheet" type="text/css" href="style.css">
    </head>
    
    <body>
      <!-- Form for logging in the users -->
    
      <div class="register-form">
        <?php
            if(isset($msg) & !empty($msg)){
                echo $msg;
            }
         ?>
    
        <h1>Login</h1>
    
        <form action="" method="post">
          <p><label>User Name :</label> <input id="username" type="text" name="username" placeholder=
          "username"></p>
    
          <p><label>Password   :</label> <input id="password" type="password" name="password"
          placeholder="password"></p><a class="btn" href="register.php">Signup</a> <input class=
          "btn register" type="submit" name="submit" value="Login">
        </form>
      </div><?php }
    
    
       ?>
    </body>
    </html>
    

    A "Join" is what I get when I google it but that doesn't seem right. Could someone help?

    • VladNeacsu
      VladNeacsu about 9 years
      What do you mean by 'after their lab results'. And off topic, in the future encrypt passwords and also look into the mysqli library
  • Kevin Krouse
    Kevin Krouse almost 12 years
    The XMLBeans xsd2inst tool will generate an instance from a schema. xmlbeans.apache.org/docs/2.4.0/guide/tools.html#xsd2inst
  • Gail Hartle
    Gail Hartle about 9 years
    Thanks for the mysqli suggestions. I'm still mucking it up though. its going to a test.php page, which doesn't exist because its the html at the bottom. With the old code, the url would stay the same but the page would change to the greeting echo. The new one seems to want to go to the test.php page which is what's in the form but is nonexistant since its built in the login.php page. I know, I'm probably dense, but do really appreciate your help.