cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
uday_guntupalli
Level VIII

Parse XML Help

All, 
   I have some XML, I would like to parse using JSL. I am not familiar with XML, so pardon my ignorance. 


   <Table><Rule DayName=\!"Sunday\!" Val1=\!"1\!"/>

 

   What I tried is the following: 

 

Parse XML( Test,
			On Element( "Table", Start Tag( New Table( XML Attr( "Table" ) ) ) ),
			On Element("Rule",End Tag( New Column( XML Attr( "DayName" ), Set Values( Parse( XML Text() ) ) ) ) )
		 );

  I know, I wold have to add one more rule using On Element to parse the "Val1" attribute, but that is not working, what I would like the output to be is : 

 

image.png

Best
Uday
1 ACCEPTED SOLUTION

Accepted Solutions
Craige_Hales
Super User

Re: Parse XML Help

test data

Test =
"\[
<Table>
    <Rule DayName="Sunday" Val1="1"/>
    <Rule DayName="Monday" Val1="2"/>
    <Rule DayName="Tuesday" Val1="3"/>
</Table>
]\";

You can get what you asked for like this:


Parse XML( Test,
    On Element( "Table", Start Tag( dt1 = New Table( XML Attr( "Table" ) ) ) ),
    On Element( "Rule", End Tag( New Column( XML Attr( "DayName" ), Set Values( Eval List( {XML Attr( "Val1" )} ) ) ) ) )
);

one wayone way

But I think a better intepretation of the file might look like this:

Parse XML( Test,
    On Element( "Table", Start Tag( dt2 = New Table( XML Attr( "Table" ), New Column( "DayName" ), New Column( "Val1" ) ) ) ),
    On Element(
        "Rule",
        End Tag(
            dt2 << addrow( 1 );
            dt2:DayName = XML Attr( "DayName" );
            dt2:Val1 = XML Attr( "Val1" );
        )
    )
);

Another wayAnother way

(You don't want the parse(...); the example in the scripting index that uses it also has a JSL matrix in the XML file that needs the parse. Your example has a single number, in quotation marks. You could use the num() function to make the conversion so the column would be numeric.   dt2:Val1 =num( XML Attr( "Val1" ));  )

Craige

View solution in original post

1 REPLY 1
Craige_Hales
Super User

Re: Parse XML Help

test data

Test =
"\[
<Table>
    <Rule DayName="Sunday" Val1="1"/>
    <Rule DayName="Monday" Val1="2"/>
    <Rule DayName="Tuesday" Val1="3"/>
</Table>
]\";

You can get what you asked for like this:


Parse XML( Test,
    On Element( "Table", Start Tag( dt1 = New Table( XML Attr( "Table" ) ) ) ),
    On Element( "Rule", End Tag( New Column( XML Attr( "DayName" ), Set Values( Eval List( {XML Attr( "Val1" )} ) ) ) ) )
);

one wayone way

But I think a better intepretation of the file might look like this:

Parse XML( Test,
    On Element( "Table", Start Tag( dt2 = New Table( XML Attr( "Table" ), New Column( "DayName" ), New Column( "Val1" ) ) ) ),
    On Element(
        "Rule",
        End Tag(
            dt2 << addrow( 1 );
            dt2:DayName = XML Attr( "DayName" );
            dt2:Val1 = XML Attr( "Val1" );
        )
    )
);

Another wayAnother way

(You don't want the parse(...); the example in the scripting index that uses it also has a JSL matrix in the XML file that needs the parse. Your example has a single number, in quotation marks. You could use the num() function to make the conversion so the column would be numeric.   dt2:Val1 =num( XML Attr( "Val1" ));  )

Craige