2012-09-18 17 views
23

ちょうど私のXMLクラスから始めて、私のエラーの解決策を見つけるのに少し面倒です。私はこのエラーが発生します: "ルート要素に続く文書のマークアップは整形式でなければなりません。 開始位置:6:2"。(XML)ルート要素に続く文書内のマークアップは整形式でなければなりません。開始位置:6:2

あらゆるヒントやヘルプがあればいいです。 XMLで

<?xml version="1.0" encoding="UTF-8"?> 
<heading> 
The Twelve Days of Christmas 
</heading> 

<song> //OxyGen highlights "<song>" as the error, but i'm not sure I understand. 
    <Day ="One"> 
     <verse> 
    On the first day of Christmas, my true love sent to me, a partridge in a pear tree. 
     </verse> 
    </Day> 

    <Day="Two"> 
     <verse> 
    On the second day of Christmas, my true love sent to me 
    Two turtle doves 
    and a partridge in a pear tree. 
     </verse> 
    </Day> 

    <Day="Three"> 
     <verse> 
    On the third day of Christmas, my true love sent to me 
    Three French hens, 
    two turtle doves 
    And a partridge in a pear tree. 
     </verse> 
    </Day> 

    <Day="Four"> 
     <verse> 
    On the fourth day of Christmas, my true love sent to me 
    Four calling birds, 
    three French hens, 
    two turtle doves 
    And a partridge in a pear tree. 
     </verse> 
    </Day> 

    <Day="Fifth"> 
     <verse> 
    On the fifth day of Christmas, my true love sent to me 
    Five golden rings. 
    Four calling birds, 
    three French hens, 
    two turtle doves 
    And a partridge in a pear tree. 
     </verse> 
    </Day> 

    <Day="Sixth"> 
     <verse> 
    On the sixth day of Christmas, my true love gave to me 
    Six geese a-laying, 
    Five golden rings. 
    Four calling birds, 
    three French hens, 
    two turtle doves 
    And a partridge in a pear tree. 
     </verse> 
    </Day> 

    <Day="Seventh"> 
     <verse> 
    On the seventh day of Christmas, my true love gave to me 
    Seven swans a-swimming, 
    six geese a-laying, 
    Five golden rings. 
    Four calling birds, 
    three French hens, 
    two turtle doves 
    And a partridge in a pear tree. 
     </verse> 
    </Day> 

    <Day="Eighth"> 
     <verse> 
    On the eighth day of Christmas, my true love gave to me 
    Eight maids a-milking, 
    seven swans a-swimming, 
    six geese a-laying, 
    Five golden rings. 
    Four calling birds, 
    three French hens, 
    two turtle doves 
    And a partridge in a pear tree. 
     </verse> 
    </Day> 

    <Day="Ninth"> 
     <verse> 
    On the ninth day of Christmas, my true love gave to me 
    Nine ladies dancing, 
    eight maids a-milking, 
    seven swans a-swimming, 
    six geese a-laying, 
    Five golden rings. 
    Four calling birds, 
    three French hens, 
    two turtle doves 
    And a partridge in a pear tree. 
     </verse> 
    </Day> 

    <Day="Tenth"> 
     <verse> 
    On the tenth day of Christmas, my true love gave to me 
    Ten lords a-leaping, 
    nine ladies dancing, 
    eight maids a-milking, 
    seven swans a-swimming, 
    six geese a-laying, 
    Five golden rings. 
    Four calling birds, 
    three French hens, 
    two turtle doves 
    And a partridge in a pear tree. 
     </verse> 
    </Day> 

    <Day="Eleventh"> 
     <verse> 
    On the eleventh day of Christmas, my true love gave to me 
    Eleven pipers piping, 
    ten lords a-leaping, 
    nine ladies dancing, 
    eight maids a-milking, 
    seven swans a-swimming, 
    six geese a-laying, 
    Five golden rings. 
    Four calling birds, 
    three French hens, 
    two turtle doves 
    And a partridge in a pear tree. 
     </verse> 
    </Day> 

    <Day="Twelfth"> 
     <verse> 
    On the twelfth day of Christmas, my true love gave to me 
    Twelve drummers drumming, 
    eleven pipers piping, 
    ten lords a-leaping, 
    nine ladies dancing, 
    eight maids a-milking, 
    seven swans a-swimming, 
    six geese a-laying, 
    Five golden rings. 
    Four calling birds, 
    three French hens, 
    two turtle doves 
    And a partridge in a pear tree. 
     </verse> 
    </Day> 

</song> 

答えて

56

だけのルート要素が存在することができます - headingsong - 次の2つがあります。

あなたのようなものに再構築した場合:

<?xml version="1.0" encoding="UTF-8"?> 
<song> 
<heading> 
The Twelve Days of Christmas 
</heading> 
.... 
</song> 

(他の問題があるかもしれませんが)ルートレベルで整形式XMLに関するエラーが消えるはずです。

+0

をすごい、*手のひらを顔に当てる*どうもありがとう、私は考えることができる唯一のものです。 – trtmerlin

+0

多くの時間を節約できます。どうもありがとう – bisw

-4

文字列「strOutputは」正しいXML構造を有していることを保証した後、あなたがこれを行うことができます:

Matcher junkMatcher = (Pattern.compile("^([\\W]+)<")).matcher(strOutput); 
strOutput = junkMatcher.replaceFirst("<"); 
関連する問題