我正在尝试使用SAX解析一个简单的XML文档,我收到以下错误:
org.xml.sax.SAXParseException:尾随部分不允许使用内容。
我已经检查了XML,看起来很好,在结束标记之后没有任何内容(甚至没有空格)。这就是我开始解析的方式(虽然我认为不应该有这个问题......):
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
xr.setContentHandler(new SLATemplateParsingHandler(this, xr));
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(XML.trim()));
xr.parse(is);
任何想法可能出错?
谢谢,
伊万
编辑:我使用w3schools XML验证器来检查我的XML,它说它没有错误。这是XML:
<?xml version='1.0' encoding='utf-8' ?>
<SLA xmlns="http://www.ibm.com/wsla" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.ibm.com/wsla WSLA.xsd" name="Sample WSLA document" >
<Parties>
<ServiceProvider name="service_provider">
<!-- should be filled up -->
</ServiceProvider>
<ServiceConsumer name="service_consumer">
<!-- should be filled up -->
</ServiceConsumer>
</Parties>
<ServiceDefinition name='SampleService'>
<Schedule name='businessdayschedule'>
<Period>
<Start>2008-11-02T20:50:00</Start>
<End>2009-11-20T20:50:00</End>
</Period>
<Interval>
<MilliSeconds>4000</MilliSeconds>
</Interval>
</Schedule>
<Schedule name="hourlyschedule">
<Period>
<Start>2008-11-30T14:00:00.000-05:00</Start>
<End>2008-12-31T14:00:00.000-05:00</End>
</Period>
<Interval>
<Minutes>60</Minutes>
</Interval>
</Schedule>
<Schedule name="availabilityschedule">
<Period>
<Start>2008-11-30T14:00:00.000-05:00</Start>
<End>2008-12-31T14:00:00.000-05:00</End>
</Period>
<Interval>
<Minutes>1</Minutes>
</Interval>
</Schedule>
<Schedule name="5minuteschedule">
<Period>
<Start>2008-11-30T14:00:00.000-05:00</Start>
<End>2008-12-31T14:00:00.000-05:00</End>
</Period>
<Interval>
<Minutes>5</Minutes>
</Interval>
</Schedule>
<WSDLSOAPOperation name='SampleOperation'>
<!-- SLA PARAMETERS -->
<!-- the current usage of cpu (for that process) -->
<SLAParameter name="Performance" type="double" unit="KHz">
<!-- POSSIBLE MAPPING TO Hz -->
<Metric>performance_metric</Metric>
</SLAParameter>
<!-- the cpu clock speed -->
<SLAParameter name="ClockSpeed" type="double" unit="MHz">
<!-- POSSIBLE MAPPING TO GHz -->
<Metric>clockspeed_metric</Metric>
</SLAParameter>
<!-- the total memory consumption -->
<SLAParameter name="TotalMemoryConsumption" type="double" unit="Mbit">
<!-- POSSIBLE MAPPING TO KBit -->
<Metric>total_memory_consumption_metric</Metric>
</SLAParameter>
<!-- response time -->
<SLAParameter name="ResponseTime" type="double" unit="milliseconds">
<!-- POSSIBLE MAPPING TO seconds -->
<Metric>response_time_metric</Metric>
</SLAParameter>
<!-- availability -->
<SLAParameter name="Availability" type="double" unit="percent">
<Metric>availability_metric</Metric>
</SLAParameter>
<!-- overload percentage -->
<SLAParameter name="OverloadPercentage" type="float" unit="percent">
<Metric>overload_percentage_metric</Metric>
</SLAParameter>
<!-- transaction rate (transactions/hour) -->
<!-- POSSIBLE MAPPING TO transactions/second -->
<SLAParameter name="TransactionRate" type="float" unit="transactions/hour">
<Metric>transactions_metric</Metric>
</SLAParameter>
<!-- availability - current downtime -->
<SLAParameter name="Av_CurrentDownTime" type="long" unit="minutes">
<!-- POSSIBLE MAPPING TO hours -->
<Metric>current_down_time_metric</Metric>
</SLAParameter>
<!-- availability - uptime ratio -->
<SLAParameter name="Av_UpTimeRatio" type="float">
<Metric>up_time_ratio_metric</Metric>
</SLAParameter>
<!-- error rate (the total number of internal server errors divided by the total number of requests during fice minute period) -->
<SLAParameter name="ErrorRate" type="float">
<Metric>error_rate_metric</Metric>
</SLAParameter>
<!-- number of CPU cores -->
<SLAParameter name="CPUCores" type="long">
<Metric>cpu_cores_metric</Metric>
</SLAParameter>
<!-- METRICS -->
<!-- the total memory consumption -->
<Metric name="total_memory_consumption_metric" type="double" unit="Mbit">
<Source>ServiceProvider</Source>
<MeasurementDirective resultType="double" xsi:type="StatusRequest">
<RequestURI> ***unused*** </RequestURI>
</MeasurementDirective>
</Metric>
<!-- <Metric name="usage_cost_metric" type="double" unit="Euro"> <Source>ServiceProvider</Source> <Function resultType="double" xsi:type="Times"> <Operand> <Metric> total_memory_consumption_metric </Metric> </Operand> <Operand> <Constant> UsageCostPerUnitInEuro </Constant> </Operand> </Function> </Metric> -->
<!-- <Metric name="penalty_cost_metric" type="long" unit="Euro"> <Source>ServiceProvider</Source> <MeasurementDirective resultType="double" xsi:type="StatusRequest"> <RequestURI> ***unused*** </RequestURI> </MeasurementDirective> </Metric> -->
<!-- cpu used for the process -->
<Metric name="performance_metric" type="double" unit="KHz">
<Source>ServiceProvider</Source>
<Function resultType="double" xsi:type="Times">
<Operand>
<Metric>process_cpu_load_metric</Metric>
</Operand>
<Operand>
<Function resultType="double" xsi:type="Divide">
<Operand>
<Metric>clock_speed_metric</Metric>
</Operand>
<Operand>
<LongScalar>100</LongScalar>
</Operand>
</Function>
</Operand>
</Function>
</Metric>
<!-- available clock speed -->
<Metric name="clockspeed_metric" type="double" unit="MHz">
<Source>ServiceProvider</Source>
<Function resultType="double" xsi:type="Times">
<Operand>
<Metric>clock_speed_metric</Metric>
</Operand>
<Operand>
<LongScalar>1</LongScalar>
</Operand>
</Function>
</Metric>
<!-- percentage of cpu-usage for the process -->
<Metric name="process_cpu_load_metric" type="double" unit="percent">
<Source>ServiceProvider</Source>
<MeasurementDirective resultType="double" xsi:type="StatusRequest">
<RequestURI> ***unused*** </RequestURI>
</MeasurementDirective>
</Metric>
<!-- clock speed of the cpu the process is running on -->
<Metric name="clock_speed_metric" type="double" unit="MHz">
<Source>ServiceProvider</Source>
<MeasurementDirective resultType="double" xsi:type="StatusRequest">
<RequestURI> ***unused*** </RequestURI>
</MeasurementDirective>
</Metric>
<!-- space free for use on the storage device -->
<!-- <Metric name="free_Diskspace" type="double" unit="percent"> <Source>ServiceProvider</Source> <MeasurementDirective resultType="double" xsi:type="StatusRequest"> <RequestURI> ***unused*** </RequestURI> </MeasurementDirective> </Metric> -->
<!-- space used by this specific customer -->
<!-- <Metric name="user_Diskspace" type="double" unit="GHz"> <Source>ServiceProvider</Source> <MeasurementDirective resultType="double" xsi:type="StatusRequest"> <RequestURI> ***unused*** </RequestURI> </MeasurementDirective> </Metric> -->
<!-- availability -->
<Metric name="availability_metric" type="double" unit="percent">
<Source>ServiceProvider</Source>
<MeasurementDirective resultType="double" xsi:type="StatusRequest">
<RequestURI> ***unused*** </RequestURI>
</MeasurementDirective>
</Metric>
<!-- overload percentage -->
<Metric name="overload_percentage_metric" type="float" unit="percent">
<Source>ServiceProvider</Source>
<Function xsi:type="PercentageGreaterThanThreshold" resultType="float">
<Metric>UtilizationTimeSeries</Metric>
<Value>
<FloatScalar>0.8</FloatScalar>
<!-- 80% -->
</Value>
</Function>
</Metric>
<Metric name="UtilizationTimeSeries" type="TS">
<Source>ServiceProvider</Source>
<Function xsi:type="TSConstructor" resultType="float">
<Schedule>businessdayschedule</Schedule>
<Metric>ProbedUtilization</Metric>
<Window>12</Window>
</Function>
</Metric>
<Metric name="ProbedUtilization" type="float">
<Source>ServiceProvider</Source>
<MeasurementDirective xsi:type="Gauge" resultType="float">
<MeasurementURI> ***unused*** </MeasurementURI>
</MeasurementDirective>
</Metric>
<!-- transactions -->
<Metric name="transactions_metric" type="long" unit="transactions/hour">
<Source>ServiceProvider</Source>
<Function xsi:type="Minus" resultType="double">
<Operand>
<Function xsi:type="TSSelect" resultType="long">
<Operand>
<Metric>SumTransactionTimeSeries</Metric>
</Operand>
<Element>0</Element>
</Function>
</Operand>
<Operand>
<Function xsi:type="TSSelect" resultType="long">
<Operand>
<Metric>SumTransactionTimeSeries</Metric>
</Operand>
<Element>-1</Element>
</Function>
</Operand>
</Function>
</Metric>
<Metric name="SumTransactionTimeSeries" type="TS" unit="transactions">
<Source>ServiceProvider</Source>
<Function xsi:type="TSConstructor" resultType="TS">
<Schedule>hourlyschedule</Schedule>
<Metric>SumTransactions</Metric>
<Window>2</Window>
</Function>
</Metric>
<!-- response time -->
<Metric name="response_time_metric" type="long" unit="milliseconds">
<Source>ServiceProvider</Source>
<Function xsi:type="Minus" resultType="double">
<Operand>
<Function xsi:type="TSSelect" resultType="long">
<Operand>
<Metric>SumResponseTimeTimeSeries</Metric>
</Operand>
<Element>0</Element>
</Function>
</Operand>
<Operand>
<Function xsi:type="TSSelect" resultType="long">
<Operand>
<Metric>SumResponseTimeTimeSeries</Metric>
</Operand>
<Element>-1</Element>
</Function>
</Operand>
</Function>
</Metric>
<Metric name="SumResponseTimeTimeSeries" type="TS" unit="milliseconds">
<Source>ServiceProvider</Source>
<Function xsi:type="TSConstructor" resultType="TS">
<Schedule>hourlyschedule</Schedule>
<Metric>SumResponseTime</Metric>
<Window>2</Window>
</Function>
</Metric>
<Metric name="SumTransactions" type="long" unit="tansactions">
<Source>ServiceProvider</Source>
<MeasurementDirective xsi:type="InvocationCount" resultType="long"/>
</Metric>
<Metric name="SumResponseTime" type="long" unit="milliseconds">
<Source>ServiceProvider</Source>
<MeasurementDirective xsi:type="SumResponseTime" resultType="long"/>
</Metric>
<!-- current down time -->
<Metric name="current_down_time_metric" type="long" unit="minutes">
<Source>ServiceProvider</Source>
<Function xsi:type="Span" resultType="double">
<Metric>StatusTimeSeries</Metric>
<Value>
<LongScalar>0</LongScalar>
</Value>
</Function>
</Metric>
<!-- uptime ratio -->
<Metric name="up_time_ratio_metric" type="long">
<Source>ServiceProvider</Source>
<Function xsi:type="Minus" resultType="double">
<Operand>
<LongScalar>1</LongScalar>
</Operand>
<Operand>
<Function xsi:type="Divide" resultType="long">
<Operand>
<Function xsi:type="ValueOccurs" resultType="long">
<Metric>StatusTimeSeries</Metric>
<Value>
<LongScalar>0</LongScalar>
</Value>
</Function>
</Operand>
<Operand>
<LongScalar>1440</LongScalar>
</Operand>
</Function>
</Operand>
</Function>
</Metric>
<Metric name="StatusTimeSeries" type="TS">
<Source>ServiceProvider</Source>
<Function xsi:type="TSConstructor" resultType="TS">
<Schedule>availabilityschedule</Schedule>
<Metric>MeasuredStatus</Metric>
<Window>1440</Window>
</Function>
</Metric>
<Metric name="MeasuredStatus" type="long">
<Source>ServiceProvider</Source>
<MeasurementDirective xsi:type="StatusRequest" resultType="integer">
<RequestURI> ***unused*** </RequestURI>
</MeasurementDirective>
</Metric>
<!-- error rate -->
<Metric name="error_rate_metric" type="float">
<Source>ServiceProvider</Source>
<Function xsi:type="TSConstructor">
<Schedule>5minuteschedule</Schedule>
<Metric>GetErrorRate</Metric>
</Function>
</Metric>
<Metric name="GetErrorRate" type="float">
<Source>ServiceProvider</Source>
<Function xsi:type="Divide" resultType="long">
<Operand>
<Metric>InternalErrors</Metric>
</Operand>
<Operand>
<Metric>SumTransactions</Metric>
</Operand>
</Function>
</Metric>
<Metric name="InternalErrors" type="long">
<Source>ServiceProvider</Source>
<MeasurementDirective xsi:type="StatusRequest" resultType="integer">
<RequestURI> ***unused*** </RequestURI>
</MeasurementDirective>
</Metric>
<!-- CPU cores -->
<Metric name="cpu_cores_metric" type="long">
<Source>ServiceProvider</Source>
<MeasurementDirective xsi:type='StatusRequest' resultType='long'>
<RequestURI> ***unused*** </RequestURI>
</MeasurementDirective>
</Metric>
<WSDLFile>/SLA/ServiceDefinition[@name='SampleService']/WSDLSOAPOperation[@name='SampleOperation']/WSDLFile</WSDLFile>
<SOAPBindingName>/SLA/ServiceDefinition[@name='SampleService']/WSDLSOAPOperation[@name='SampleOperation']/SOAPBindingName</SOAPBindingName>
<SOAPOperationName>/SLA/ServiceDefinition[@name='SampleService']/WSDLSOAPOperation[@name='SampleOperation']/SOAPOperationName</SOAPOperationName>
</WSDLSOAPOperation>
</ServiceDefinition>
<Obligations>
<!-- SERVICE LEVEL OBJECTIVES -->
<ServiceLevelObjective name="PerformanceSLO">
<Obliged>service_provider</Obliged>
<Validity>
<Start>2008-11-03T14:00:00</Start>
<End>2009-11-18T14:00:00</End>
</Validity>
<Expression>
<Predicate xsi:type="Greater">
<SLAParameter>Performance</SLAParameter>
<Value>600</Value>
</Predicate>
</Expression>
<EvaluationEvent>NewValue</EvaluationEvent>
</ServiceLevelObjective>
<ServiceLevelObjective name="ResponseTimeSLO">
<Obliged>service_provider</Obliged>
<Validity>
<Start>2008-11-03T14:00:00</Start>
<End>2009-11-18T14:00:00</End>
</Validity>
<Expression>
<Predicate xsi:type="Less">
<SLAParameter>ResponseTime</SLAParameter>
<Value>600</Value>
</Predicate>
</Expression>
<EvaluationEvent>NewValue</EvaluationEvent>
</ServiceLevelObjective>
<ServiceLevelObjective name="AvailabilitySLO">
<Obliged>service_provider</Obliged>
<Validity>
<Start>2008-11-03T14:00:00</Start>
<End>2009-11-18T14:00:00</End>
</Validity>
<Expression>
<Predicate xsi:type="Less">
<SLAParameter>Availability</SLAParameter>
<Value>99</Value>
</Predicate>
</Expression>
<EvaluationEvent>NewValue</EvaluationEvent>
</ServiceLevelObjective>
<!-- ACTION GUARANTEES -->
<ActionGuarantee name="PerformanceGuarantee">
<Obliged>service_provider</Obliged>
<Expression>
<Predicate xsi:type='Violation'>
<ServiceLevelObjective>PerformanceSLO</ServiceLevelObjective>
</Predicate>
</Expression>
<EvaluationEvent>NewValue</EvaluationEvent>
<QualifiedAction>
<Party>/SLA/Obligations/ActionGuarantee[@name='PerformanceGuarantee']/QualifiedAction/Party</Party>
<Action xsi:type='Notification' actionName='notification'>
<NotificationType>Violation</NotificationType>
<CausingGuarantee>PerformanceSLO</CausingGuarantee>
<SLAParameter>Performance</SLAParameter>
</Action>
</QualifiedAction>
<ExecutionModality>Always</ExecutionModality>
</ActionGuarantee>
<ActionGuarantee name="ResponseTimeGuarantee">
<Obliged>service_provider</Obliged>
<Expression>
<Predicate xsi:type='Violation'>
<ServiceLevelObjective>ResponseTimeSLO</ServiceLevelObjective>
</Predicate>
</Expression>
<EvaluationEvent>NewValue</EvaluationEvent>
<QualifiedAction>
<Party>/SLA/Obligations/ActionGuarantee[@name='ResponseTimeGuarantee']/QualifiedAction/Party</Party>
<Action xsi:type='Notification' actionName='notification'>
<NotificationType>Violation</NotificationType>
<CausingGuarantee>ResponseTimeSLO</CausingGuarantee>
<SLAParameter>ResponseTime</SLAParameter>
</Action>
</QualifiedAction>
<ExecutionModality>Always</ExecutionModality>
</ActionGuarantee>
<ActionGuarantee name="AvailabilityGuarantee">
<Obliged>service_provider</Obliged>
<Expression>
<Predicate xsi:type='Violation'>
<ServiceLevelObjective>AvailabilitySLO</ServiceLevelObjective>
</Predicate>
</Expression>
<EvaluationEvent>NewValue</EvaluationEvent>
<QualifiedAction>
<Party>/SLA/Obligations/ActionGuarantee[@name='AvailabilityGuarantee']/QualifiedAction/Party</Party>
<Action xsi:type='Notification' actionName='notification'>
<NotificationType>Violation</NotificationType>
<CausingGuarantee>AvailabilitySLO</CausingGuarantee>
<SLAParameter>Availability</SLAParameter>
</Action>
</QualifiedAction>
<ExecutionModality>Always</ExecutionModality>
</ActionGuarantee>
</Obligations>
</SLA>