Answers.Body: <p>As Zhaph - Ben Duguid said, there is the .LXFML format which is basically an XML document detailing a LEGO model. Another format you might find of use if the .ldr format. .ldr files are used in various LEGO virtual building programs that make up what's called <a href="http://www.ldraw.org/" rel="nofollow noreferrer">the LDraw system of tools</a>. As an example of the .ldr format, this:</p>
  <p><img src="https://i.sstatic.net/NMBDt.png" alt="Simble brick assembly" /></p>
  <p>Can be generated by pasting this into a text document and renaming it .ldr:</p>
  <blockquote>
  <p>0 Brick test</p>
  <p>0 Name: Brick test.ldr</p>
  <p>0 Author: HaydenStudios</p>
  <p>0 Unofficial Model</p>
  <p>0 ROTATION CENTER 0 0 0 1 &quot;Custom&quot;</p>
  <p>0 ROTATION CONFIG 0 0</p>
  <p>1 4 50 0 0 1 0 0 0 1 0 0 0 1 3001.dat</p>
  <p>1 7 50 -8 0 1 0 0 0 1 0 0 0 1 3020.dat</p>
  <p>1 4 50 -32 0 1 0 0 0 1 0 0 0 1 3003.dat</p>
  <p>1 4 50 -56 10 1 0 0 0 1 0 0 0 1 3009.dat</p>
  <p>0</p>
  </blockquote>
  <p>All LDraw applications rely on having a base LDraw installation to refer to which contains files for 3D models of all LEGO parts available in the LDraw parts library. If you wanted to write a Javascript that interprets LDraw models, you'd need it to have an LDraw parts library stored somewhere to refer to, such as on a server.</p>
  <p>Each tool in the LDraw system of tools has its own &quot;actions&quot; that it injects into an LDraw file when you edit it. One such program, LPub, is specifically designed for making instructions for models constructed using any LDraw-compatible tool:</p>
  <p><img src="https://i.sstatic.net/4pMfk.png" alt="LEGO Car in LPub" /></p>
  <p>It allows you to set up each page, and saves your setups for each page into the LDraw file so that it can be read by any program that knows how to read LDraw files and LPub's formatting.</p>
  <p>This and the .LXFML format are the only two file formats I know of that are along the lines of what you described. One potentially deciding factor in which format to choose is the different ways they handle instructions. For LDraw files, you have to manually make the steps as you make the models, whereas LDD automatically generates the instructions. While this can save the builder a lot of time, the order in which the pieces are added may not make as much sense as if they were made manually. Whether this is a pro or con is really a matter of personal preference.</p>
  <p>Altogether, though, I'd personally recommend using LDraw files due to LEGO Digital Designer's relatively limited part library, as well as the fact that the former is generally more favored among the late teen and AFOL community.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-04T21:11:05.687Z
Answers.LastActivityDate: 2014-08-07T00:25:32.630Z
Answers.LastEditDate: 2020-06-18T08:28:58.637Z
Answers.UserDisplayName: HaydenStudios
Answers.Body: <p>Yes, there is <a href="https://bricks.stackexchange.com/q/1349/56">LXFML</a> - which is if you like an "offical" XML format for LEGO models - in that it's produced and maintained by The LEGO Group.</p>
  
  <p>The <code>.LXF</code> format used by LEGO Digital Designer is a compressed archive containing a thumbnail in .png format and a model definition file in LFXML.</p>
  
  <p>As I noted in the answer to that question, the <a href="http://news.lugnet.com/cad/ldd/?n=140" rel="nofollow noreferrer">LDD team have shared</a> both the documentation and XSD for validating this.</p>
  
  <p>Within the definition, there is scope for a <code>&lt;BuildingInstructions&gt;</code> element that can contain one or more <code>&lt;BuildingInstruction&gt;</code> elements. These in turn contain <code>&lt;steps&gt;</code> which reference one or more parts or contain sub-steps:</p>
  
  <pre><code>&lt;BuildingInstructions&gt;
    &lt;BuildingInstruction name="b6206_" cameraRefID="4"&gt;
      &lt;Step name="b6206_s1"&gt;
        &lt;Step name="b6206_s2"&gt;
          &lt;PartRef partRefID="0"/&gt;
        &lt;/Step&gt;
        &lt;PartRef partRefID="1"/&gt;
        &lt;PartRef partRefID="2"/&gt;
      &lt;/Step&gt;
      &lt;Step&gt;
        &lt;PartRef partRefID="3"/&gt;
      &lt;/Step&gt;
    &lt;/BuildingInstruction&gt;
  &lt;/BuildingInstructions&gt;
  </code></pre>
  
  <p>Note that the <code>&lt;PartRefs&gt;</code> are Ids to parts in the <code>&lt;Model&gt;</code> elements, which define the actual element, colour and orientation.</p>
  
  <p>The default steps created within LDD have been known to be a little hit and miss, adding multiple elements at once and not always visibly or in a valid order (although that may have improved since I last used it for step creation).</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-06T18:12:29.260Z
Answers.Text: Ah, very good! I didn't realize there was documentation on LDD files, and that it came closer than .ldr files to what randomblink was asking for. I'll go ahead and edit my answer to acknowledge this.
Answers.UserDisplayName: HaydenStudios
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-05T09:40:46.253Z
Answers.LastActivityDate: 2014-08-20T20:28:57.330Z
Answers.LastEditDate: 2017-04-13T12:47:56.213Z
Answers.UserDisplayName: Zhaph - Ben Duguid
Body: <p>I've seen some pretty neat applications using customized XML formats. There is a Musical Notation XML so that a user can create sheet music on XML. With the right software, that XML can be converted to ACTUAL sheet music, and other plugins even convert this XML to a MIDI output that plays the music.</p>
  
  <p>I'm wondering if there is an XML format for Lego? I would assume it would follow a procedural output where Step 1 is take a 2x2 piece and attach peg Top-Left to 4x1 piece bottom slot. Or something similar.</p>
  
  <p>Just wondering... if there isn't, I feel like there should be. With a Javascript app written for it you could have people converting Lego instruction books to XML or creating custom instruction books with walk-thrus available with a Javascript app.</p>
  
Tags: <software><instructions>
Title: Is there an XML format for Lego?
UserDisplayName: randomblink
ThreadText: # Is there an XML format for Lego?
  
  (Asked by: username_0 on 2014-08-04)
  
  I've seen some pretty neat applications using customized XML formats. There is a Musical Notation XML so that a user can create sheet music on XML. With the right software, that XML can be converted to ACTUAL sheet music, and other plugins even convert this XML to a MIDI output that plays the music.
  
  I'm wondering if there is an XML format for Lego? I would assume it would follow a procedural output where Step 1 is take a 2x2 piece and attach peg Top-Left to 4x1 piece bottom slot. Or something similar.
  
  Just wondering... if there isn't, I feel like there should be. With a Javascript app written for it you could have people converting Lego instruction books to XML or creating custom instruction books with walk-thrus available with a Javascript app.
  
  **Tags:** software, instructions
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2014-08-05. Score: 9 | Accepted answer
  
  Yes, there is [LXFML](https://bricks.stackexchange.com/q/1349/56) - which is if you like an "offical" XML format for LEGO models - in that it's produced and maintained by The LEGO Group.
  
  The `.LXF` format used by LEGO Digital Designer is a compressed archive containing a thumbnail in .png format and a model definition file in LFXML.
  
  As I noted in the answer to that question, the [LDD team have shared](http://news.lugnet.com/cad/ldd/?n=140) both the documentation and XSD for validating this.
  
  Within the definition, there is scope for a `<BuildingInstructions>` element that can contain one or more `<BuildingInstruction>` elements. These in turn contain `<steps>` which reference one or more parts or contain sub-steps:
  
  ```
  <BuildingInstructions>
    <BuildingInstruction name="b6206_" cameraRefID="4">
      <Step name="b6206_s1">
        <Step name="b6206_s2">
          <PartRef partRefID="0"/>
        </Step>
        <PartRef partRefID="1"/>
        <PartRef partRefID="2"/>
      </Step>
      <Step>
        <PartRef partRefID="3"/>
      </Step>
    </BuildingInstruction>
  </BuildingInstructions>
  
  ```
  
  Note that the `<PartRefs>` are Ids to parts in the `<Model>` elements, which define the actual element, colour and orientation.
  
  The default steps created within LDD have been known to be a little hit and miss, adding multiple elements at once and not always visibly or in a valid order (although that may have improved since I last used it for step creation).
  
  > **Comments:**
  > **username_1**: Ah, very good! I didn't realize there was documentation on LDD files, and that it came closer than .ldr files to what username_0 was asking for. I'll go ahead and edit my answer to acknowledge this.  
  
  ---
  
  ### Answer by username_1 on 2014-08-04. Score: 5
  
  As username_2 said, there is the .LXFML format which is basically an XML document detailing a LEGO model. Another format you might find of use if the .ldr format. .ldr files are used in various LEGO virtual building programs that make up what's called [the LDraw system of tools](http://www.ldraw.org/). As an example of the .ldr format, this:
  
  ![Simble brick assembly](https://i.sstatic.net/NMBDt.png)
  
  Can be generated by pasting this into a text document and renaming it .ldr:
  
  > 0 Brick test
  >
  > 0 Name: Brick test.ldr
  >
  > 0 Author: username_1
  >
  > 0 Unofficial Model
  >
  > 0 ROTATION CENTER 0 0 0 1 "Custom"
  >
  > 0 ROTATION CONFIG 0 0
  >
  > 1 4 50 0 0 1 0 0 0 1 0 0 0 1 3001.dat
  >
  > 1 7 50 -8 0 1 0 0 0 1 0 0 0 1 3020.dat
  >
  > 1 4 50 -32 0 1 0 0 0 1 0 0 0 1 3003.dat
  >
  > 1 4 50 -56 10 1 0 0 0 1 0 0 0 1 3009.dat
  >
  > 0
  
  All LDraw applications rely on having a base LDraw installation to refer to which contains files for 3D models of all LEGO parts available in the LDraw parts library. If you wanted to write a Javascript that interprets LDraw models, you'd need it to have an LDraw parts library stored somewhere to refer to, such as on a server.
  
  Each tool in the LDraw system of tools has its own "actions" that it injects into an LDraw file when you edit it. One such program, LPub, is specifically designed for making instructions for models constructed using any LDraw-compatible tool:
  
  ![LEGO Car in LPub](https://i.sstatic.net/4pMfk.png)
  
  It allows you to set up each page, and saves your setups for each page into the LDraw file so that it can be read by any program that knows how to read LDraw files and LPub's formatting.
  
  This and the .LXFML format are the only two file formats I know of that are along the lines of what you described. One potentially deciding factor in which format to choose is the different ways they handle instructions. For LDraw files, you have to manually make the steps as you make the models, whereas LDD automatically generates the instructions. While this can save the builder a lot of time, the order in which the pieces are added may not make as much sense as if they were made manually. Whether this is a pro or con is really a matter of personal preference.
  
  Altogether, though, I'd personally recommend using LDraw files due to LEGO Digital Designer's relatively limited part library, as well as the fact that the former is generally more favored among the late teen and AFOL community.
  
  
  ---
  
  