Lone Wolf Development Forums  

Go Back   Lone Wolf Development Forums > Realm Works Forums > Realm Works Discussion
Register FAQ Community Today's Posts Search

Notices

Reply
 
Thread Tools Display Modes
EightBitz
Senior Member
 
Join Date: May 2013
Posts: 1,458

Old November 4th, 2016, 11:50 PM
There was a recent post by Rob where he indicated there was an upcoming export feature for XML, and if nothing else, this would allow us to print. This offers the possibility that we'll have to roll our own print formatting. Not something I'm thrilled about, but hey, I'll take what I can get.

I've been poking around with XML features in PowerShell, and some of it is easier than I thought it would be while some of it is still a bit frustrating. I'm not a professional programmer, but I dabble, and I know there are others who wish to print, so I'm sharing what I'm learning in my struggles. If anyone else with more programming experience wishes to chime in, I'm all for that.

If you're going to follow along with me, I suggest loading the PowerShell ISE. It's not installed by default, but you can install it through the "Add or remove programs" control panel and selecting "Turn Windows Features on or off." Find "PowerShell ISE", and select it. (I'm assuming you're using Windows 8 or Windows 10.)

And just to clarify, this isn't meant to be an in-depth, comprehensive tutorial. I'm learning as I go, so this is a very basic introduction for myself that I'm sharing with you.

First of all, importing an XML file into PowerShell as an XML object is rather easy. To practice, I'm working with a Hero Lab portfolio, hence my variable name in the following code snippet. I'm also using a Mutants and Masterminds 3E portfolio with multiple characters.

(Paste this in the top half of the ISE window.)
Code:
[xml]$Portfolio = Get-Content -Path <filename>
That's it. That loads the file as an XML object. Click the green play button to run the script.
Now, in the bottom window, you can type "$Portfolio" and press the enter key. You'll see the child nodes ("xml" and "document") as column headers.

Now type "$Portfolio.document.public" (I'm skipping ahead with the child nodes), and you'll see the child nodes for program, localization and character. Under the character column, you'll see the list of character names in curly brackets. Mine have spaces in the names (e.g. "The Rook").

So now, in the top half, I can add the following code to the script:

Code:
$Rook = $Portfolio.document.public.character | Where-Object {$_.name -eq "The Rook"}
Now, if I type $Rook in the bottom half of the ISE window, I can see a list of the child nodes and their values for this single character.

Now, say I want to get The Rook's attributes. In Mutants and Masterminds 3E, the attributes are Strength, Stamina, Agility and Dexterity. And for each attribute, the available elements are: text, base, modified, cost.

So if I want to get The Rook's strength, I can add the following code to the script.

Code:
$Strength = $Rook.attributes.attribute | Where-Object {$_.name -eq "Strength"}
Now, in the bottom half of the ISE window, I can type $Strength, and I'll see the different values. Or I can type $Strength.text, $Strength.base, $Strength.modified, or Strength.cost.

This is basically how you can drill-down through the XML object to get the values you want. To see the full hierarchy, you can load the XML file into UltraEdit (License required) or NotePad++ (Free) or something similar.

I wrote a recursive function that does kind of a raw text dump. It's not pretty, but if you want to play with the function, here it is:

Code:
Function ShowXML($PassedObject,$PassedOutput,$PassedIndent) {
    "$PassedIndent### " + $PassedObject.name + " ###" >> $PassedOutput
    if ($PassedObject.innertext -ne "") {
       $PassedIndent + $PassedObject.innertext >> $PassedOutput
    } elseif ($PassedParam.text -ne "") {
       $PassedIndent + $PassedObject.text >> $PassedOutput
    } # if ($PassedObject.innertext)

   if ($PassedObject.HasChildNodes) {
       $PassedIndent = $PassedIndent + "   "
       foreach ($Child in $PassedObject.ChildNodes) {
          ShowXML $Child $PassedOutput $PassedIndent
      } # foreach ($Child in $PassedObject.ChildNodes)
   } # if ($PassedObject.HasChildNodes)

} # Function ShowXML

# Main Script Starts Here
$InputFile = "<Original XML filename>"
$OutputFile = "<File to contain the raw dump>"
[xml]$Portfolio = Get-Content -Path $InputFile
"XML Output" > $OutputFile
$Indent = ""
ShowXML $Portfolio $OutputFile $Indent
EightBitz is offline   #1 Reply With Quote
Viking2054
Senior Member
 
Join Date: Apr 2014
Location: California
Posts: 295

Old November 5th, 2016, 12:04 AM
It may be a bit premature, except as a learning exercise. Besides, most of this is probably handled best with a CSS (cascading style sheet) and a web browser. There is another format you can use, but I'm betting the CSS format is the way to go for printing.

We would probably need LWD to provide us with the xml tags they are using for differentiating the various pieces of information though.
Viking2054 is offline   #2 Reply With Quote
EightBitz
Senior Member
 
Join Date: May 2013
Posts: 1,458

Old November 5th, 2016, 12:18 AM
Quote:
Originally Posted by Viking2054 View Post
It may be a bit premature, except as a learning exercise. Besides, most of this is probably handled best with a CSS (cascading style sheet) and a web browser. There is another format you can use, but I'm betting the CSS format is the way to go for printing.

We would probably need LWD to provide us with the xml tags they are using for differentiating the various pieces of information though.
Nothing wrong with a learning exercise. :-)
EightBitz is offline   #3 Reply With Quote
kbs666
Senior Member
 
Join Date: Oct 2014
Location: Chicago, IL
Posts: 1,690

Old November 5th, 2016, 08:39 AM
Once we find out how the XML is going to be formatted I can put together a basic CSS to allow plain viewing and printing. People should be able to customize that into handouts and other things pretty easily.
kbs666 is offline   #4 Reply With Quote
ShadowChemosh
Senior Member
Volunteer Data File Contributor
 
Join Date: Jan 2010
Location: Chicago, IL (USA)
Posts: 10,729

Old November 5th, 2016, 09:50 AM
What you would really want to look at is XSLT tools designed to translate XML into something else like HTML. XSLT and XQuery where made to do exactly this to translate the XML Data into readable forms.

Similar to HL and Custom Output the RW output "may" even be able to call the XSLT directly for you making it even easier. Plus "Custom Output" options could be listed as things to download from the Content Market. Meaning you could have different output for different styles. Need it like a book format or a statblock could have different "Output" options to select.

Hero Lab Resources:
Pathfinder - d20pfsrd and Pathfinder Pack Setup
3.5 D&D (d20) - Community Server Setup
5E D&D - Community Server Setup
Hero Lab Help - Hero Lab FAQ, Editor Tutorials and Videos, Editor & Scripting Resources.
Created by the community for the community
- Realm Works kickstarter backer (Alpha Wolf) and Beta tester.
- d20 HL package volunteer editor.
ShadowChemosh is offline   #5 Reply With Quote
EightBitz
Senior Member
 
Join Date: May 2013
Posts: 1,458

Old November 5th, 2016, 12:04 PM
Cool. I appreciate all the input. Really looking forward to finally being able to print, and to whatever can make that easier.

Last edited by EightBitz; November 5th, 2016 at 12:04 PM. Reason: typo
EightBitz is offline   #6 Reply With Quote
rob
Senior Member
Lone Wolf Staff
 
Join Date: May 2005
Posts: 8,232

Old November 5th, 2016, 01:49 PM
We will be providing TWO distinct output formats. One is intended exclusively for importing content back into RW. This one will be for hardcore users only. The other is targeted specifically for users who just want to consume their content in a simpler, more streamlined manner - like PRINTING. The two formats will be VERY similar to each other, but they will diverge in areas where it makes sense based on the intended use. And, yes, there will be a formal XSD of the format.

We'll be sharing more details on this stuff in the not-to-distant future...
rob is offline   #7 Reply With Quote
EightBitz
Senior Member
 
Join Date: May 2013
Posts: 1,458

Old November 5th, 2016, 01:53 PM
Quote:
Originally Posted by rob View Post
We will be providing TWO distinct output formats. One is intended exclusively for importing content back into RW. This one will be for hardcore users only. The other is targeted specifically for users who just want to consume their content in a simpler, more streamlined manner - like PRINTING. The two formats will be VERY similar to each other, but they will diverge in areas where it makes sense based on the intended use. And, yes, there will be a formal XSD of the format.

We'll be sharing more details on this stuff in the not-to-distant future...
A much appreciated reply, Rob. Thank you.
EightBitz is offline   #8 Reply With Quote
DaFranker
Member
 
Join Date: Nov 2014
Posts: 49

Old November 6th, 2016, 03:14 PM
Quote:
Originally Posted by rob View Post
We will be providing TWO distinct output formats. One is intended exclusively for importing content back into RW. This one will be for hardcore users only. The other is targeted specifically for users who just want to consume their content in a simpler, more streamlined manner - like PRINTING. The two formats will be VERY similar to each other, but they will diverge in areas where it makes sense based on the intended use. And, yes, there will be a formal XSD of the format.

We'll be sharing more details on this stuff in the not-to-distant future...
Oh! That's epic news, since I was under the impression the export/import would be fully limited to exporting to/from Realms and wouldn't be usable to produce external formats yet.

Heh, any chance this will let the more enterprising among us cook up their own Player Web View conversion tool? I didn't catch from previous posts whether the export tools would allow us to pick Revealed content or exclude hidden snippets and other GM-only elements from an export.
DaFranker is offline   #9 Reply With Quote
rob
Senior Member
Lone Wolf Staff
 
Join Date: May 2005
Posts: 8,232

Old November 6th, 2016, 04:08 PM
Quote:
Originally Posted by DaFranker View Post
Heh, any chance this will let the more enterprising among us cook up their own Player Web View conversion tool? I didn't catch from previous posts whether the export tools would allow us to pick Revealed content or exclude hidden snippets and other GM-only elements from an export.
Yes, this will be possible. Limiting the export to only revealed content is an important aspect of the mechanism.
rob is offline   #10 Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 10:32 AM.


Powered by vBulletin® - Copyright ©2000 - 2024, vBulletin Solutions, Inc.
wolflair.com copyright ©1998-2016 Lone Wolf Development, Inc. View our Privacy Policy here.