Menu

#20 XML transducer sometimes excludes spaces in data

open
nobody
None
5
2007-01-17
2007-01-17
Anonymous
No

Following code

public static INode convertXMLStringToNode(String contents) throws Exception
{
XMLTransducer xmlTransducer = new XMLTransducer();
StringTransducerAdapter adapter = new StringTransducerAdapter( contents, // the String data
xmlTransducer );
IMetaCollection meta = MetaFactory.createMetaCollection( LogCOPSEventConstants.COPS_TRANSACTION );

meta.setTransducer( adapter );
meta.get();

return meta;
}

parses following XML

strXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><COPSTransaction>" +
"<VersionSpecification>1.2.0</VersionSpecification>" +
"<DateTimeAccessed>2007-01-16T15:33:51.000-08:00</DateTimeAccessed>" +
"<UTCTimeOffset>-8.0</UTCTimeOffset><User>Vgwwyq_JMS</User>" +
"<UserNumber>70535</UserNumber><MachineName>Xplijfehwm</MachineName>" +
"<IPAddress>206.50.233.198</IPAddress><ApplicationNumber>322</ApplicationNumber>" +
"<ApplicationSubsection>Ukisoamdlinxxyjmnyqe</ApplicationSubsection>" +
"<ApplicationSubsectionNumber>325</ApplicationSubsectionNumber>" +
"<DataSourceType>positional text file</DataSourceType>" +
"<DataSourceName>Phqhxnlykhxpomctjjihnbasmb</DataSourceName>" +
"<DataSourceContainerName>Fhhiic</DataSourceContainerName>" +
"<DataStoreExecutable>Kiafdo</DataStoreExecutable>" +
"<UniqueIdentifierForMessage/>" +
"<ClientUniqueIdentifierForMessage>Bcsgxadlphufqqlgelbanpqjdt</ClientUniqueIdentifierForMessage>" +
"<ActionData><ActionName>Timeout</ActionName><Count>48036</Count><Description>Lyhpuqxp</Description></ActionData>" +
"<ActionData><ActionName>Lockout</ActionName><Count>18909</Count><Description>Vsuewb</Description></ActionData>" +
"<ActionData><ActionName>Timeout</ActionName><Count>78019</Count><Description>Ueebdk</Description></ActionData>" +
"<ActionData><ActionName>Impersonate Customer</ActionName><Count>26624</Count><Description>Ifti</Description>" +
"<ActionParameter><ActionParameterName>Customer Screen Name</ActionParameterName><Direction>I</Direction><Value>Yeeeh</Value></ActionParameter></ActionData>" +
"<ActionData><ActionName>Reset Password</ActionName><Count>27116</Count><Description>Nigbjl</Description>" +
"<ActionParameter><ActionParameterName>Result</ActionParameterName><Direction>O</Direction><Value>Edlohwvm</Value></ActionParameter></ActionData>" +
"<ActionData><ActionName>Password Challenge</ActionName><Count>79155</Count><Description>Asuapqu</Description>" +
"<ActionParameter><ActionParameterName>Result</ActionParameterName><Direction>O</Direction><Value>Voil</Value></ActionParameter></ActionData>" +
"<ActionData><ActionName>Impersonate Customer</ActionName><Count>70772</Count><Description>Hcabvyor</Description>" +
"<ActionParameter><ActionParameterName>Customer Screen Name</ActionParameterName><Direction>I</Direction><Value>Ydau</Value></ActionParameter></ActionData>" +
"<ActionData><ActionName>Timeout</ActionName><Count>67889</Count><Description>Ytwklb</Description></ActionData>" +
"<ActionData><ActionName>Impersonate Customer</ActionName><Count>62048</Count><Description>Wnbtjnw</Description>" +
"<ActionParameter><ActionParameterName>Customer Screen Name</ActionParameterName><Direction>I</Direction><Value>Uefeqxgl</Value></ActionParameter></ActionData>" +
"<ActionData><ActionName>Login</ActionName><Count>65645</Count><Description>Fntnkdy</Description>" +
"<ActionParameter><ActionParameterName>Result</ActionParameterName><Direction>O</Direction><Value>Ibujgc</Value></ActionParameter></ActionData>" +
"</COPSTransaction>";

in such a way, that the tag

"<ActionParameter><ActionParameterName>Customer Screen Name</ActionParameterName><Direction>I</Direction><Value>Ydau</Value></ActionParameter></ActionData>" +

parses "Customer Screen Name" as "Customer ScreenName".
The erros is in XMLTransducer in the following method

//*************************************************************************
public void characters(char[] ch,
int start,
int length)
{
//System.out.println( getClass().getName()+": chars "+(new String( ch, start, length ).trim()));
INode node = ( INode ) stack.peek();

if (( null == node.getValue() ) || (bStartingElement)) {
node.setValue( new String( ch, start, length ).trim() );
bStartingElement = false;
}
else {
StringBuffer sb = new StringBuffer( length + node.getValue().toString().length() );
sb.append( node.getValue() ).append( ch, start, length );
node.setValue( sb.toString().trim() );
}
}

which should't do trim().

THis was reproduced on Windows Server 2003 with Java 1.5.0.9 and on Fedora Core 6 with Java 1.5.0.9

Discussion


Log in to post a comment.