Наследование:
System.ApplicationException
Показать файл
Открыть проект
Открытые методы
Метод | Описание | |
---|---|---|
XmlFormatException ( string message ) : System |
Описание методов
XmlFormatException()
публичный метод
public XmlFormatException ( string message ) : System | ||
message | string | |
Результат | System |
I am trying to implement Apache Qpid into our architecture and I am having trouble reading in a properties file.
Properties props = new Properties();
props.loadFromXML(this.getClass().getResourceAsStream(«hello.properties»));
loadfromxml is throwing me an error, here is the stack trace:
> java.util.InvalidPropertiesFormatException:
> org.xml.sax.SAXParseException: Content is not allowed in prolog. at
> java.util.XMLUtils.load(XMLUtils.java:56) at
> java.util.Properties.loadFromXML(Properties.java:852) at
> com.irad.message.system.HelloTest.runTest(HelloTest.java:29) at
> com.irad.message.system.HelloTest.main(HelloTest.java:23) Caused by:
> org.xml.sax.SAXParseException: Content is not allowed in prolog. at
> com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
> at
> com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:174)
> at
> com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:388)
> at
> com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1427)
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:1036)
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:647)
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
> at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
> at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
> at
> com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
> at
> com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:232)
> at
> com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284)
> at java.util.XMLUtils.getLoadingDoc(XMLUtils.java:82) at
> java.util.XMLUtils.load(XMLUtils.java:54) ... 3 more
Here is the hello.properties file:
java.naming.factory.initial=org.apache.qpid.jndi.PropertiesFileInitialContextFactory
connectionfactory.qpidConnectionfactory= amqp://guest:guest@clientid/test?brokerlist='tcp://localhost:5672'
destination.topicExchange = amq.topic
What am I doing wrong? I copied the code snippet from the documentation page of Qpid.
asked Dec 11, 2012 at 17:34
4
You are using Properties.loadFromXML to load a TEXT file as XML, and it’s telling you the XML file you’ve given it is malformed.
Next time when you get errors like this, do a google search for ‘java loadfromxml’. It will take you to the javadocs manual on how to use it and you will see that the parameters you are feeding it is incorrect:
http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Properties.html#loadFromXML%28java.io.InputStream%29
The above link says:
The XML document must have the following DOCTYPE declaration:
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
Change your properties file to be of correct format, and then you’ll be on your way to figuring out the next error.
answered Dec 11, 2012 at 17:41
Eric LeschinskiEric Leschinski
145k95 gold badges412 silver badges332 bronze badges
5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
<?xml version="1.0" encoding="UTF-8"?> <report> <eeprom version="ENHANCED PBB/ЂB cor/dens v10.12" datetime=""></eeprom> <sn>015.15.01.002</sn> <file path="internalanalog.tar" type="tar"> <point> <x>-11,0000000</x> <y>1,6000000</y> </point> <point> <x>-0,0500000</x> <y>0,0000000</y> </point> </file> <file path="externaldensity.cor" type="cor"> <surface> <a0>94,5305710</a0> <a1>-0,0142365</a1> <a2>-0,0043975</a2> <a11>-0,0000980</a11> <a22>0,0001461</a22> <a12>-0,0000220</a12> <p>1,0000000</p> </surface> <surface> <a0>-266,8311768</a0> <a1>-3,8060381</a1> <a2>1,8994861</a2> <a11>0,0000000</a11> <a22>0,0000000</a22> <a12>0,0000000</a12> <p>3,0000000</p> </surface> <surface> <a0>0,0000000</a0> <a1>0,0000000</a1> <a2>0,0000000</a2> <a11>-0,0004314</a11> <a22>0,0000001</a22> <a12>0,0000000</a12> <p>6,0000000</p> </surface> <surface> <a0>-13,4954958</a0> <a1>0,0428321</a1> <a2>-0,0312684</a2> <a11>0,0000000</a11> <a22>0,0000000</a22> <a12>0,0000000</a12> <p>7,0000000</p> </surface> <surface> <a0>1000,0000000</a0> <a1>0,0000000</a1> <a2>100,0000000</a2> <a11>0,1000000</a11> <a22>10,0000000</a22> <a12>0,1000000</a12> <p>5,0000000</p> </surface> </file> <file path="internalpressure.tar" type="tar"> <point> <x>2360,0000000</x> <y>0,0000000</y> </point> <point> <x>3532,0000000</x> <y>58,4000015</y> </point> <point> <x>4547,0000000</x> <y>103,8000031</y> </point> <point> <x>5764,0000000</x> <y>158,6999969</y> </point> <point> <x>6877,0000000</x> <y>209,0000000</y> </point> <point> <x>7900,0000000</x> <y>255,1999969</y> </point> <point> <x>8982,0000000</x> <y>304,0000000</y> </point> <point> <x>10074,0000000</x> <y>352,7999878</y> </point> <point> <x>11149,0000000</x> <y>400,8999939</y> </point> </file> <file path="externaldensity.tar" type="tar"> <point> <x>0,8943808</x> <y>0,0000000</y> </point> <point> <x>1,0004297</x> <y>1,0000000</y> </point> <point> <x>1,0124259</x> <y>1,1160001</y> </point> <point> <x>1,0233793</x> <y>1,2240000</y> </point> <point> <x>1,0292079</x> <y>1,2840000</y> </point> <point> <x>1,0409085</x> <y>1,4030000</y> </point> <point> <x>1,0498325</x> <y>1,4930000</y> </point> <point> <x>1,0583036</x> <y>1,5800000</y> </point> <point> <x>1,0686287</x> <y>1,6900001</y> </point> <point> <x>1,0780404</x> <y>1,7860010</y> </point> <point> <x>1,0865008</x> <y>1,8940001</y> </point> <point> <x>1,0918074</x> <y>1,9540000</y> </point> </file> <file path="externalcoriol.tar" type="tar"> <point> <x>0,0000000</x> <y>0,0000000</y> </point> <point> <x>1,0423599</x> <y>8,8731651</y> </point> </file> <file path="externalrotate.tar" type="tar"> <point> <x>0,2771824</x> <y>0,0000000</y> </point> <point> <x>51,5987129</x> <y>-0,8832195</y> </point> <point> <x>102,9263687</x> <y>-2,8315117</y> </point> <point> <x>161,3097382</x> <y>-4,0044746</y> </point> <point> <x>203,9690857</x> <y>-3,2529044</y> </point> <point> <x>250,3599396</x> <y>-4,8435221</y> </point> <point> <x>302,4907227</x> <y>-6,9018602</y> </point> <point> <x>351,8223267</x> <y>-5,4620886</y> </point> <point> <x>396,1837158</x> <y>-6,5484858</y> </point> </file> <file path="internalrgr.tar" type="tar"> <point> <x>1,0000000</x> <y>0,0000000</y> </point> <point> <x>1,1160051</x> <y>-7,7440825</y> </point> <point> <x>1,2240053</x> <y>-4,7421026</y> </point> <point> <x>1,2839999</x> <y>-1,4837382</y> </point> <point> <x>1,4029999</x> <y>0,6799557</y> </point> <point> <x>1,4930004</x> <y>3,0734160</y> </point> <point> <x>1,5800005</x> <y>4,8079190</y> </point> <point> <x>1,6899979</x> <y>6,9035168</y> </point> <point> <x>1,7860079</x> <y>7,7395725</y> </point> <point> <x>1,8939825</x> <y>9,9293804</y> </point> <point> <x>1,9540000</x> <y>8,4871855</y> </point> </file> <file path="internalCorKRoP.tar" type="tar"> <point> <x>0,0000000</x> <y>1,0000000</y> </point> <point> <x>1,0000000</x> <y>1,0000000</y> </point> </file> </report> |
Я получаю XML-строку от контроллера моего веб-API, который построен, как показано:
private string CreateXDoc(IEnumerable<PassedJSONConverted> passed)
{
XNamespace xmlns = "http://host.adp.com";
var doc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
var jobListElement = new XElement(xmlns + "JobXML");
foreach (var objectItem in passed)
{
var loopElement = new XElement(xmlns + "JobsXML", new XElement(xmlns + "ID", objectItem.ID.ToString()), new XElement(xmlns + "Name", objectItem.Name), new XElement(xmlns + "Age", objectItem.Age.ToString()), new XElement(xmlns + "JobTitle", objectItem.JobTitle), new XElement(xmlns + "StartDate", objectItem.StartDate));
jobListElement.Add(loopElement);
}
doc.Add(jobListElement);
//Format without n's
return doc.ToString(SaveOptions.DisableFormatting);
}
Это хорошо, и XML установлен как показано:
- <JobXML xmlns="http://host.xxx.com">
- <JobsXML>
<ID>1</ID>
<Name>Dave</Name>
<Age>23</Age>
<JobTitle>Developer</JobTitle>
<StartDate>10/24/2013 6:40:28 AM</StartDate>
</JobsXML>
- <JobsXML>
<ID>2</ID>
<Name>John</Name>
<Age>44</Age>
<JobTitle>QA</JobTitle>
<StartDate>10/24/2013 6:40:28 AM</StartDate>
</JobsXML>
- <JobsXML>
<ID>3</ID>
<Name>Dave</Name>
<Age>23</Age>
<JobTitle>Senior Developer</JobTitle>
<StartDate>10/24/2013 6:40:28 AM</StartDate>
</JobsXML>
</JobXML>
Когда я возвращаю это как строку и пытаюсь выполнить ее синтаксический анализ на xDoc, как показано ниже:
private static string HandleResponse(HttpWebResponse httpResponse)
{
using (var responseReader = new StreamReader(httpResponse.GetResponseStream(), Encoding.UTF8))
{
string responsePayload = responseReader.ReadToEnd();
var newxDoc = XDocument.Parse(responsePayload);
return responsePayload;
}
}
Строка ‘responsePayLoad’ во время выполнения устанавливается как показано:
"<JobXML xmlns="http://host.adp.com"><JobsXML><ID>1</ID><Name>Dave</Name><Age>23</Age><JobTitle>Developer</JobTitle><StartDate>10/24/2013 6:45:22 AM</StartDate></JobsXML><JobsXML><ID>2</ID><Name>John</Name><Age>44</Age><JobTitle>QA</JobTitle><StartDate>10/24/2013 6:45:22 AM</StartDate></JobsXML><JobsXML><ID>3</ID><Name>Dave</Name><Age>23</Age><JobTitle>Senior Developer</JobTitle><StartDate>10/24/2013 6:45:22 AM</StartDate></JobsXML></JobXML>"
Это дает мне исключение в объекте ‘newxDoc’:
XmlException не обрабатывается. Данные на корневом уровне недействительны. Строка 1, позиция 1.
Может ли кто-нибудь сказать мне, где я ошибаюсь?