Changeset 32565 in vbox
- Timestamp:
- Sep 16, 2010 2:39:24 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/cpp/xml.h
r30746 r32565 565 565 566 566 private: 567 friend class XmlMemParser; 567 568 friend class XmlFileParser; 568 569 friend class XmlFileWriter; … … 587 588 588 589 xmlParserCtxtPtr m_ctxt; 590 }; 591 592 /* 593 * XmlMemParser 594 * 595 */ 596 597 class RT_DECL_CLASS XmlMemParser : public XmlParserBase 598 { 599 public: 600 XmlMemParser(); 601 ~XmlMemParser(); 602 603 void read(const void* pvBuf, int cbSize, const iprt::MiniString &strFilename, Document &doc); 589 604 }; 590 605 -
trunk/src/VBox/Main/include/ovfreader.h
r30157 r32565 403 403 { 404 404 public: 405 OVFReader(const void *pvBuf, int cbSize, const iprt::MiniString &path); 405 406 OVFReader(const iprt::MiniString &path); 406 407 … … 413 414 xml::Document m_doc; 414 415 416 void parse(); 415 417 void LoopThruSections(const xml::ElementNode *pReferencesElem, const xml::ElementNode *pCurElem); 416 418 void HandleDiskSection(const xml::ElementNode *pReferencesElem, const xml::ElementNode *pSectionElem); -
trunk/src/VBox/Main/xml/ovfreader.cpp
r29893 r32565 31 31 32 32 /** 33 * Constructor. This parses the given XML file out of the memory. Throws lots of exceptions 34 * on XML or OVF invalidity. 35 * @param pvBuf the memory buffer to parse 36 * @param cbSize the size of the memory buffer 37 * @param path path to a filename for error messages. 38 */ 39 OVFReader::OVFReader(const void *pvBuf, int cbSize, const MiniString &path) 40 : m_strPath(path) 41 { 42 xml::XmlMemParser parser; 43 parser.read(pvBuf, cbSize, 44 m_strPath, 45 m_doc); 46 /* Start the parsing */ 47 parse(); 48 } 49 50 /** 33 51 * Constructor. This opens the given XML file and parses it. Throws lots of exceptions 34 52 * on XML or OVF invalidity. … … 41 59 parser.read(m_strPath, 42 60 m_doc); 43 61 /* Start the parsing */ 62 parse(); 63 } 64 65 void OVFReader::parse() 66 { 44 67 const xml::ElementNode *pRootElem = m_doc.getRootElement(); 45 68 if ( !pRootElem -
trunk/src/VBox/Runtime/r3/xml.cpp
r30746 r32565 1340 1340 //////////////////////////////////////////////////////////////////////////////// 1341 1341 // 1342 // XmlMemParser class 1343 // 1344 //////////////////////////////////////////////////////////////////////////////// 1345 1346 XmlMemParser::XmlMemParser() 1347 : XmlParserBase() 1348 { 1349 } 1350 1351 XmlMemParser::~XmlMemParser() 1352 { 1353 } 1354 1355 /** 1356 * Parse the given buffer and fills the given Document object with its contents. 1357 * Throws XmlError on parsing errors. 1358 * 1359 * The document that is passed in will be reset before being filled if not empty. 1360 * 1361 * @param pvBuf in: memory buffer to parse. 1362 * @param cbSize in: size of the memory buffer. 1363 * @param strFilename in: name fo file to parse. 1364 * @param doc out: document to be reset and filled with data according to file contents. 1365 */ 1366 void XmlMemParser::read(const void* pvBuf, int cbSize, 1367 const iprt::MiniString &strFilename, 1368 Document &doc) 1369 { 1370 GlobalLock lock; 1371 // global.setExternalEntityLoader(ExternalEntityLoader); 1372 1373 const char *pcszFilename = strFilename.c_str(); 1374 1375 doc.m->reset(); 1376 if (!(doc.m->plibDocument = xmlCtxtReadMemory(m_ctxt, 1377 (const char*)pvBuf, 1378 cbSize, 1379 pcszFilename, 1380 NULL, // encoding = auto 1381 XML_PARSE_NOBLANKS))) 1382 throw XmlError(xmlCtxtGetLastError(m_ctxt)); 1383 1384 doc.refreshInternals(); 1385 } 1386 1387 //////////////////////////////////////////////////////////////////////////////// 1388 // 1342 1389 // XmlFileParser class 1343 1390 // … … 1346 1393 struct XmlFileParser::Data 1347 1394 { 1348 xmlParserCtxtPtr ctxt;1349 1395 iprt::MiniString strXmlFilename; 1350 1396 1351 1397 Data() 1352 1398 { 1353 if (!(ctxt = xmlNewParserCtxt()))1354 throw std::bad_alloc();1355 1399 } 1356 1400 1357 1401 ~Data() 1358 1402 { 1359 xmlFreeParserCtxt(ctxt);1360 ctxt = NULL;1361 1403 } 1362 1404 }; … … 1431 1473 ReadContext context(pcszFilename); 1432 1474 doc.m->reset(); 1433 if (!(doc.m->plibDocument = xmlCtxtReadIO(m ->ctxt,1475 if (!(doc.m->plibDocument = xmlCtxtReadIO(m_ctxt, 1434 1476 ReadCallback, 1435 1477 CloseCallback, … … 1438 1480 NULL, // encoding = auto 1439 1481 XML_PARSE_NOBLANKS))) 1440 throw XmlError(xmlCtxtGetLastError(m ->ctxt));1482 throw XmlError(xmlCtxtGetLastError(m_ctxt)); 1441 1483 1442 1484 doc.refreshInternals();
Note:
See TracChangeset
for help on using the changeset viewer.