XML文件要有根标签(错误)的代码解决分享

使用的xml文档如下

<?xml version="1.0" encoding="UTF-8"?>  
  <SearchConstraints>  
    <Begin>glucose</Begin>  
    <End>Ethanol</End>  
    <Interface>name</Interface>  
    <IntermediatesInclude number="0"></IntermediatesInclude>  
    <IntermediatesExclude> number="0"></IntermediatesExclude>  
    <Organisms type="all"></Organisms>  
    <KShort>10</KShort>  
  </SearchConstraints>  
  <StoPList>  
    <StoP>  
      <Source id="glucose"></Source>  
      <Target id="Ethanol"></Target>  
      <RouteList>  
      </RouteList>  
    </StoP>  
  </StoPList>

问题所在:没有加根标签呀!XML文件只能有一个根标签!
把xml改成下面这样就ok了,也就是加一个Document标签,将先前的两个根标签SearchConstraints和StoPList都放到Document标签的下面,从而整个XML文件只有一个根标签。

<?xml version="1.0" encoding="UTF-8"?>  
<Document>  
  <SearchConstraints>  
    <Begin>glucose</Begin>  
    <End>Ethanol</End>  
    <Interface>name</Interface>  
    <IntermediatesInclude number="0"></IntermediatesInclude>  
    <IntermediatesExclude> number="0"></IntermediatesExclude>  
    <Organisms type="all"></Organisms>  
    <KShort>10</KShort>  
  </SearchConstraints>  
  <StoPList>  
    <StoP>  
      <Source id="glucose"></Source>  
      <Target id="Ethanol"></Target>  
      <RouteList>  
      </RouteList>  
    </StoP>  
  </StoPList>  
</Document>

以上就是XML文件要有根标签(错误)的代码解决分享的详细内容,更多请关注www.sxiaw.com其它相关文章!