(XML) 文档中根元素后面的标记必须格式正确。出发地点:6:2
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12475012/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
(XML) The markup in the document following the root element must be well-formed. Start location: 6:2
提问by trtmerlin
Just started out in my XML class and having a bit of trouble finding a solution to my error. I get this error: "The markup in the document following the root element must be well-formed. Start location: 6:2".
刚开始在我的 XML 类中找到解决我的错误的方法有点麻烦。我收到此错误:“文档中根元素后面的标记必须格式正确。起始位置:6:2”。
Any kind of hint or help would be great.
任何形式的提示或帮助都会很棒。
<?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>
回答by Oded
In XML there can be only oneroot element - you have two - headingand song.
在 XML 中只能有一个根元素——你有两个——heading和song.
If you restructure to something like:
如果您重组为以下内容:
<?xml version="1.0" encoding="UTF-8"?>
<song>
<heading>
The Twelve Days of Christmas
</heading>
....
</song>
The error about well-formed XML on the root level should disappear (though there may be other issues).
根级别上有关格式良好的 XML 的错误应该会消失(尽管可能还有其他问题)。
回答by Mohsen Abasi
After insuring that the string "strOutput" has a correct XML structure, you can do this:
在确保字符串“strOutput”具有正确的 XML 结构后,您可以执行以下操作:
Matcher junkMatcher = (Pattern.compile("^([\W]+)<")).matcher(strOutput);
strOutput = junkMatcher.replaceFirst("<");

