Changeset 49028 in vbox
- Timestamp:
- Oct 10, 2013 12:55:06 PM (11 years ago)
- svn:sync-xref-src-repo-rev:
- 89794
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/cpp/xml.h
r48862 r49028 399 399 const char *getPrefix() const; 400 400 const char *getNamespaceURI() const; 401 bool nameEquals (const char *pcszNamespace, const char *pcsz) const;401 bool nameEqualsNS(const char *pcszNamespace, const char *pcsz) const; 402 402 bool nameEquals(const char *pcsz) const 403 403 { 404 return nameEquals (NULL, pcsz);405 } 406 bool nameEqualsN(const char *pcsz Namespace, const char *pcsz, size_t cchMax) const;404 return nameEqualsNS(NULL, pcsz); 405 } 406 bool nameEqualsN(const char *pcsz, size_t cchMax, const char *pcszNamespace = NULL) const; 407 407 408 408 const char *getValue() const; … … 534 534 AttributeNode(const AttributeNode &x); // no copying 535 535 536 /** For storing attribute names with namespace prefix.537 * Only used if with non-default namespace specified. */538 RTCString m_strKey;539 540 536 friend class Node; 541 537 friend class ElementNode; … … 557 553 { 558 554 public: 559 int getChildElements(ElementNodesList &children, 560 const char *pcszMatch = NULL) const; 561 562 const ElementNode *findChildElement(const char *pcszNamespace, 563 const char *pcszMatch) const; 555 int getChildElements(ElementNodesList &children, const char *pcszMatch = NULL) const; 556 557 const ElementNode *findChildElementNS(const char *pcszNamespace, const char *pcszMatch) const; 564 558 const ElementNode *findChildElement(const char *pcszMatch) const 565 559 { 566 return findChildElement (NULL, pcszMatch);560 return findChildElementNS(NULL, pcszMatch); 567 561 } 568 562 const ElementNode *findChildElementFromId(const char *pcszId) const; … … 610 604 * (default) match any namespace. When using a 611 605 * path, this matches all elements along the way. 606 * @param pcszAttribNamespace The namespace prefix to apply to the attribute, 607 * NULL (default) match any namespace. 612 608 * @see findChildElementP and findAttributeValue 613 609 */ 614 610 const char *findChildElementAttributeValueP(const char *pcszPath, const char *pcszAttribute, 615 const char *pcszPathNamespace = NULL) const 611 const char *pcszPathNamespace = NULL, 612 const char *pcszAttributeNamespace = NULL) const 616 613 { 617 614 const ElementNode *pElem = findChildElementP(pcszPath, pcszPathNamespace); 618 615 if (pElem) 619 return pElem->findAttributeValue(pcszAttribute );616 return pElem->findAttributeValue(pcszAttribute, pcszAttributeNamespace); 620 617 return NULL; 621 618 } … … 695 692 696 693 697 const AttributeNode *findAttribute(const char *pcszMatch ) const;694 const AttributeNode *findAttribute(const char *pcszMatch, const char *pcszNamespace = NULL) const; 698 695 /** Find the first attribute with the given name, returning its value string. 699 696 * @returns Pointer to the attribute string value. 700 697 * @param pcszName The attribute name. 698 * @param pcszNamespace The namespace name, default is NULL which means 699 * anything goes. 701 700 * @see getAttributeValue 702 701 */ 703 const char *findAttributeValue(const char *pcszName ) const704 { 705 const AttributeNode *pAttr = findAttribute(pcszName );702 const char *findAttributeValue(const char *pcszName, const char *pcszNamespace = NULL) const 703 { 704 const AttributeNode *pAttr = findAttribute(pcszName, pcszNamespace); 706 705 if (pAttr) 707 706 return pAttr->getValue(); … … 709 708 } 710 709 711 bool getAttributeValue(const char *pcszMatch, const char *&pcsz) const { return getAttributeValue(pcszMatch, &pcsz); } 712 bool getAttributeValue(const char *pcszMatch, RTCString &str) const; 713 bool getAttributeValuePath(const char *pcszMatch, RTCString &str) const; 714 bool getAttributeValue(const char *pcszMatch, int32_t &i) const; 715 bool getAttributeValue(const char *pcszMatch, uint32_t &i) const; 716 bool getAttributeValue(const char *pcszMatch, int64_t &i) const { return getAttributeValue(pcszMatch, &i); } 717 bool getAttributeValue(const char *pcszMatch, uint64_t &i) const; 718 bool getAttributeValue(const char *pcszMatch, bool &f) const; 710 bool getAttributeValue(const char *pcszMatch, const char *&pcsz, const char *pcszNamespace = NULL) const 711 { return getAttributeValue(pcszMatch, &pcsz, pcszNamespace); } 712 bool getAttributeValue(const char *pcszMatch, RTCString &str, const char *pcszNamespace = NULL) const 713 { return getAttributeValue(pcszMatch, &str, pcszNamespace); } 714 bool getAttributeValuePath(const char *pcszMatch, RTCString &str, const char *pcszNamespace = NULL) const 715 { return getAttributeValue(pcszMatch, &str, pcszNamespace); } 716 bool getAttributeValue(const char *pcszMatch, int32_t &i, const char *pcszNamespace = NULL) const 717 { return getAttributeValue(pcszMatch, &i, pcszNamespace); } 718 bool getAttributeValue(const char *pcszMatch, uint32_t &i, const char *pcszNamespace = NULL) const 719 { return getAttributeValue(pcszMatch, &i, pcszNamespace); } 720 bool getAttributeValue(const char *pcszMatch, int64_t &i, const char *pcszNamespace = NULL) const 721 { return getAttributeValue(pcszMatch, &i, pcszNamespace); } 722 bool getAttributeValue(const char *pcszMatch, uint64_t &u, const char *pcszNamespace = NULL) const 723 { return getAttributeValue(pcszMatch, &u, pcszNamespace); } 724 bool getAttributeValue(const char *pcszMatch, bool &f, const char *pcszNamespace = NULL) const 725 { return getAttributeValue(pcszMatch, &f, pcszNamespace); } 719 726 720 727 /** @name Variants that for clarity does not use references for output params. 721 728 * @{ */ 722 bool getAttributeValue(const char *pcszMatch, const char **ppcsz ) const;723 bool getAttributeValue(const char *pcszMatch, RTCString *pStr ) const { return getAttributeValue(pcszMatch, *pStr); }724 bool getAttributeValuePath(const char *pcszMatch, RTCString *pStr ) const { return getAttributeValuePath(pcszMatch, *pStr); }725 bool getAttributeValue(const char *pcszMatch, int32_t *pi ) const { return getAttributeValue(pcszMatch, *pi); }726 bool getAttributeValue(const char *pcszMatch, uint32_t *pu ) const { return getAttributeValue(pcszMatch, *pu); }727 bool getAttributeValue(const char *pcszMatch, int64_t *piValue ) const;728 bool getAttributeValue(const char *pcszMatch, uint64_t *pu ) const { return getAttributeValue(pcszMatch, *pu); }729 bool getAttributeValue(const char *pcszMatch, bool *pf ) const { return getAttributeValue(pcszMatch, *pf); }729 bool getAttributeValue(const char *pcszMatch, const char **ppcsz, const char *pcszNamespace = NULL) const; 730 bool getAttributeValue(const char *pcszMatch, RTCString *pStr, const char *pcszNamespace = NULL) const; 731 bool getAttributeValuePath(const char *pcszMatch, RTCString *pStr, const char *pcszNamespace = NULL) const; 732 bool getAttributeValue(const char *pcszMatch, int32_t *pi, const char *pcszNamespace = NULL) const; 733 bool getAttributeValue(const char *pcszMatch, uint32_t *pu, const char *pcszNamespace = NULL) const; 734 bool getAttributeValue(const char *pcszMatch, int64_t *piValue, const char *pcszNamespace = NULL) const; 735 bool getAttributeValue(const char *pcszMatch, uint64_t *pu, const char *pcszNamespace = NULL) const; 736 bool getAttributeValue(const char *pcszMatch, bool *pf, const char *pcszNamespace = NULL) const; 730 737 /** @} */ 731 738 -
trunk/src/VBox/Main/xml/Settings.cpp
r48983 r49028 493 493 // <ExtraDataItem name="GUI/LastWindowPostion" value="97,88,981,858"/> 494 494 Utf8Str strName, strValue; 495 if ( ((pelmExtraDataItem->getAttributeValue("name", strName))) 496 && ((pelmExtraDataItem->getAttributeValue("value", strValue))) 497 ) 495 if ( pelmExtraDataItem->getAttributeValue("name", strName) 496 && pelmExtraDataItem->getAttributeValue("value", strValue) ) 498 497 map[strName] = strValue; 499 498 else … … 521 520 flt.action = USBDeviceFilterAction_Ignore; 522 521 Utf8Str strAction; 523 if ( (pelmLevel4Child->getAttributeValue("name", flt.strName)) 524 && (pelmLevel4Child->getAttributeValue("active", flt.fActive)) 525 ) 522 if ( pelmLevel4Child->getAttributeValue("name", flt.strName) 523 && pelmLevel4Child->getAttributeValue("active", flt.fActive)) 526 524 { 527 525 if (!pelmLevel4Child->getAttributeValue("vendorId", flt.strVendorId)) … … 576 574 settings::Medium med; 577 575 Utf8Str strUUID; 578 if (! (elmMedium.getAttributeValue("uuid", strUUID)))576 if (!elmMedium.getAttributeValue("uuid", strUUID)) 579 577 throw ConfigFileError(this, &elmMedium, N_("Required %s/@uuid attribute is missing"), elmMedium.getName()); 580 578 … … 669 667 670 668 if (med.strFormat.isEmpty()) // not set with 1.4 format above, or 1.4 Custom format? 671 if (! (elmMedium.getAttributeValue("format", med.strFormat)))669 if (!elmMedium.getAttributeValue("format", med.strFormat)) 672 670 throw ConfigFileError(this, &elmMedium, N_("Required %s/@format attribute is missing"), elmMedium.getName()); 673 671 674 if (! (elmMedium.getAttributeValue("autoReset", med.fAutoReset)))672 if (!elmMedium.getAttributeValue("autoReset", med.fAutoReset)) 675 673 med.fAutoReset = false; 676 674 677 675 Utf8Str strType; 678 if ( (elmMedium.getAttributeValue("type", strType)))676 if (elmMedium.getAttributeValue("type", strType)) 679 677 { 680 678 // pre-1.4 used lower case, so make this case-insensitive … … 701 699 { 702 700 // DVD and floppy images before 1.4 had "src" attribute instead of "location" 703 if (! (elmMedium.getAttributeValue("src", med.strLocation)))701 if (!elmMedium.getAttributeValue("src", med.strLocation)) 704 702 throw ConfigFileError(this, &elmMedium, N_("Required %s/@src attribute is missing"), elmMedium.getName()); 705 703 … … 707 705 } 708 706 709 if (! (elmMedium.getAttributeValue("format", med.strFormat)))707 if (!elmMedium.getAttributeValue("format", med.strFormat)) 710 708 { 711 709 // DVD and floppy images before 1.11 had no format attribute. assign the default. … … 721 719 if (fNeedsLocation) 722 720 // current files and 1.4 CustomHardDisk elements must have a location attribute 723 if (! (elmMedium.getAttributeValue("location", med.strLocation)))721 if (!elmMedium.getAttributeValue("location", med.strLocation)) 724 722 throw ConfigFileError(this, &elmMedium, N_("Required %s/@location attribute is missing"), elmMedium.getName()); 725 723 … … 745 743 { 746 744 Utf8Str strPropName, strPropValue; 747 if ( (pelmHDChild->getAttributeValue("name", strPropName)) 748 && (pelmHDChild->getAttributeValue("value", strPropValue)) 749 ) 745 if ( pelmHDChild->getAttributeValue("name", strPropName) 746 && pelmHDChild->getAttributeValue("value", strPropValue) ) 750 747 med.properties[strPropName] = strPropValue; 751 748 else … … 1302 1299 MachineRegistryEntry mre; 1303 1300 Utf8Str strUUID; 1304 if ( ((pelmChild1->getAttributeValue("uuid", strUUID))) 1305 && ((pelmChild1->getAttributeValue("src", mre.strSettingsFile))) 1306 ) 1301 if ( pelmChild1->getAttributeValue("uuid", strUUID) 1302 && pelmChild1->getAttributeValue("src", mre.strSettingsFile) ) 1307 1303 { 1308 1304 parseUUID(mre.uuid, strUUID); … … 1328 1324 { 1329 1325 DHCPServer srv; 1330 if ( (pelmServer->getAttributeValue("networkName", srv.strNetworkName)) 1331 && (pelmServer->getAttributeValue("IPAddress", srv.strIPAddress)) 1332 && (pelmServer->getAttributeValue("networkMask", srv.GlobalDhcpOptions[DhcpOpt_SubnetMask])) 1333 && (pelmServer->getAttributeValue("lowerIP", srv.strIPLower)) 1334 && (pelmServer->getAttributeValue("upperIP", srv.strIPUpper)) 1335 && (pelmServer->getAttributeValue("enabled", srv.fEnabled)) 1336 ) 1326 if ( pelmServer->getAttributeValue("networkName", srv.strNetworkName) 1327 && pelmServer->getAttributeValue("IPAddress", srv.strIPAddress) 1328 && pelmServer->getAttributeValue("networkMask", srv.GlobalDhcpOptions[DhcpOpt_SubnetMask]) 1329 && pelmServer->getAttributeValue("lowerIP", srv.strIPLower) 1330 && pelmServer->getAttributeValue("upperIP", srv.strIPUpper) 1331 && pelmServer->getAttributeValue("enabled", srv.fEnabled) ) 1337 1332 { 1338 1333 xml::NodesLoop nlOptions(*pelmServer, "Options"); … … 1351 1346 uint32_t u32Slot; 1352 1347 cfg->getAttributeValue("vm-name", strVmName); 1353 cfg->getAttributeValue("slot", (uint32_t&)u32Slot); 1354 readDhcpOptions(srv.VmSlot2OptionsM[VmNameSlotKey(strVmName, u32Slot)], 1355 *cfg); 1348 cfg->getAttributeValue("slot", u32Slot); 1349 readDhcpOptions(srv.VmSlot2OptionsM[VmNameSlotKey(strVmName, u32Slot)], *cfg); 1356 1350 } 1357 1351 llDhcpServers.push_back(srv); … … 1368 1362 xml::NodesLoop nl2(options, "Option"); 1369 1363 const xml::ElementNode *opt; 1370 while ((opt = nl2.forAllNodes()))1364 while ((opt = nl2.forAllNodes())) 1371 1365 { 1372 1366 DhcpOpt_T OptName; … … 1379 1373 opt->getAttributeValue("value", OptValue); 1380 1374 1381 map.insert( 1382 std::map<DhcpOpt_T, Utf8Str>::value_type(OptName, OptValue)); 1375 map.insert(std::map<DhcpOpt_T, Utf8Str>::value_type(OptName, OptValue)); 1383 1376 } /* end of forall("Option") */ 1384 1377 … … 1398 1391 { 1399 1392 NATNetwork net; 1400 if ( (pelmNet->getAttributeValue("networkName", net.strNetworkName)) 1401 && (pelmNet->getAttributeValue("enabled", net.fEnabled)) 1402 && (pelmNet->getAttributeValue("network", net.strNetwork)) 1403 && (pelmNet->getAttributeValue("ipv6", net.fIPv6)) 1404 && (pelmNet->getAttributeValue("ipv6prefix", net.strIPv6Prefix)) 1405 && (pelmNet->getAttributeValue("advertiseDefaultIPv6Route", net.fAdvertiseDefaultIPv6Route)) 1406 && (pelmNet->getAttributeValue("needDhcp", net.fNeedDhcpServer)) 1407 ) 1393 if ( pelmNet->getAttributeValue("networkName", net.strNetworkName) 1394 && pelmNet->getAttributeValue("enabled", net.fEnabled) 1395 && pelmNet->getAttributeValue("network", net.strNetwork) 1396 && pelmNet->getAttributeValue("ipv6", net.fIPv6) 1397 && pelmNet->getAttributeValue("ipv6prefix", net.strIPv6Prefix) 1398 && pelmNet->getAttributeValue("advertiseDefaultIPv6Route", net.fAdvertiseDefaultIPv6Route) 1399 && pelmNet->getAttributeValue("needDhcp", net.fNeedDhcpServer) ) 1408 1400 { 1409 1401 pelmNet->getAttributeValue("loopback6", net.u32HostLoopback6Offset); … … 2379 2371 readNATForwardRuleList(elmMode, nic.nat.llRules); 2380 2372 } 2381 else if ( (elmMode.nameEquals("HostInterface"))2382 || (elmMode.nameEquals("BridgedInterface")))2373 else if ( elmMode.nameEquals("HostInterface") 2374 || elmMode.nameEquals("BridgedInterface")) 2383 2375 { 2384 2376 enmAttachmentType = NetworkAttachmentType_Bridged; … … 2414 2406 { 2415 2407 Utf8Str strPropName, strPropValue; 2416 if ( (pelmModeChild->getAttributeValue("name", strPropName)) 2417 && (pelmModeChild->getAttributeValue("value", strPropValue)) 2418 ) 2408 if ( pelmModeChild->getAttributeValue("name", strPropName) 2409 && pelmModeChild->getAttributeValue("value", strPropValue) ) 2419 2410 nic.genericProperties[strPropName] = strPropValue; 2420 2411 else … … 2958 2949 /* <Property name="TCP/Ports" value="3000-3002"/> */ 2959 2950 Utf8Str strName, strValue; 2960 if ( ((pelmProperty->getAttributeValue("name", strName))) 2961 && ((pelmProperty->getAttributeValue("value", strValue))) 2962 ) 2951 if ( pelmProperty->getAttributeValue("name", strName) 2952 && pelmProperty->getAttributeValue("value", strValue)) 2963 2953 hw.vrdeSettings.mapProperties[strName] = strValue; 2964 2954 else … … 3006 2996 // legacy BIOS/IDEController (pre 1.7) 3007 2997 if ( (m->sv < SettingsVersion_v1_7) 3008 && ( (pelmBIOSChild = pelmHwChild->findChildElement("IDEController")))2998 && (pelmBIOSChild = pelmHwChild->findChildElement("IDEController")) 3009 2999 ) 3010 3000 { … … 3092 3082 readUSBDeviceFilters(*pelmUSBChild, hw.usbSettings.llDeviceFilters); 3093 3083 } 3094 else if ( (m->sv < SettingsVersion_v1_7) 3095 && (pelmHwChild->nameEquals("SATAController")) 3096 ) 3084 else if ( m->sv < SettingsVersion_v1_7 3085 && pelmHwChild->nameEquals("SATAController")) 3097 3086 { 3098 3087 bool f; 3099 if ( (pelmHwChild->getAttributeValue("enabled", f)) 3100 && (f) 3101 ) 3088 if ( pelmHwChild->getAttributeValue("enabled", f) 3089 && f) 3102 3090 { 3103 3091 StorageController sctl; … … 3116 3104 { 3117 3105 Utf8Str strLocalOrUTC; 3118 machineUserData.fRTCUseUTC = 3119 3120 } 3121 else if ( (pelmHwChild->nameEquals("UART"))3122 || (pelmHwChild->nameEquals("Uart")) // used before 1.33106 machineUserData.fRTCUseUTC = pelmHwChild->getAttributeValue("localOrUTC", strLocalOrUTC) 3107 && strLocalOrUTC == "UTC"; 3108 } 3109 else if ( pelmHwChild->nameEquals("UART") 3110 || pelmHwChild->nameEquals("Uart") // used before 1.3 3123 3111 ) 3124 3112 readSerialPorts(*pelmHwChild, hw.llSerialPorts); 3125 else if ( (pelmHwChild->nameEquals("LPT"))3126 || (pelmHwChild->nameEquals("Lpt")) // used before 1.33113 else if ( pelmHwChild->nameEquals("LPT") 3114 || pelmHwChild->nameEquals("Lpt") // used before 1.3 3127 3115 ) 3128 3116 readParallelPorts(*pelmHwChild, hw.llParallelPorts); … … 3226 3214 } 3227 3215 } 3228 } else if (pelmHwChild->nameEquals("HostPci")) { 3216 } 3217 else if (pelmHwChild->nameEquals("HostPci")) 3218 { 3229 3219 const xml::ElementNode *pelmDevices; 3230 3220 … … 3537 3527 const xml::ElementNode *pDriveChild; 3538 3528 Utf8Str strTmp; 3539 if ( ((pDriveChild = pelmHwChild->findChildElement("Image"))) 3540 && (pDriveChild->getAttributeValue("uuid", strTmp)) 3541 ) 3529 if ( (pDriveChild = pelmHwChild->findChildElement("Image")) != NULL 3530 && pDriveChild->getAttributeValue("uuid", strTmp)) 3542 3531 parseUUID(att.uuid, strTmp); 3543 3532 else if ((pDriveChild = pelmHwChild->findChildElement("HostDrive"))) … … 3567 3556 { 3568 3557 bool fEnabled; 3569 if ( (pelmHwChild->getAttributeValue("enabled", fEnabled)) 3570 && (fEnabled) 3571 ) 3558 if ( pelmHwChild->getAttributeValue("enabled", fEnabled) 3559 && fEnabled) 3572 3560 { 3573 3561 // create a new floppy controller and attach a floppy "attached device" … … 3585 3573 const xml::ElementNode *pDriveChild; 3586 3574 Utf8Str strTmp; 3587 if ( ((pDriveChild = pelmHwChild->findChildElement("Image"))) 3588 && (pDriveChild->getAttributeValue("uuid", strTmp)) 3589 ) 3575 if ( (pDriveChild = pelmHwChild->findChildElement("Image")) 3576 && pDriveChild->getAttributeValue("uuid", strTmp) ) 3590 3577 parseUUID(att.uuid, strTmp); 3591 3578 else if ((pDriveChild = pelmHwChild->findChildElement("HostDrive"))) … … 3734 3721 if (pelmSnapshotChild->nameEquals("Description")) 3735 3722 snap.strDescription = pelmSnapshotChild->getValue(); 3736 else if ( (m->sv < SettingsVersion_v1_7) 3737 && (pelmSnapshotChild->nameEquals("HardDiskAttachments")) 3738 ) 3723 else if ( m->sv < SettingsVersion_v1_7 3724 && pelmSnapshotChild->nameEquals("HardDiskAttachments")) 3739 3725 readHardDiskAttachments_pre1_7(*pelmSnapshotChild, snap.storage); 3740 else if ( (m->sv >= SettingsVersion_v1_7) 3741 && (pelmSnapshotChild->nameEquals("StorageControllers")) 3742 ) 3726 else if ( m->sv >= SettingsVersion_v1_7 3727 && pelmSnapshotChild->nameEquals("StorageControllers")) 3743 3728 readStorageControllers(*pelmSnapshotChild, snap.storage); 3744 3729 else if (pelmSnapshotChild->nameEquals("Snapshots")) … … 3837 3822 { 3838 3823 Utf8Str strUUID; 3839 if ( (elmMachine.getAttributeValue("uuid", strUUID)) 3840 && (elmMachine.getAttributeValue("name", machineUserData.strName)) 3841 ) 3824 if ( elmMachine.getAttributeValue("uuid", strUUID) 3825 && elmMachine.getAttributeValue("name", machineUserData.strName)) 3842 3826 { 3843 3827 parseUUID(uuid, strUUID); -
trunk/src/VBox/Main/xml/ovfreader.cpp
r48009 r49028 91 91 } 92 92 93 if ((pTypeAttr = pRootElem->findAttribute(" xml:lang")))93 if ((pTypeAttr = pRootElem->findAttribute("lang", "xml"))) 94 94 { 95 95 pcszTypeAttr = pTypeAttr->getValue(); … … 135 135 const char *pcszTypeAttr = ""; 136 136 const xml::AttributeNode *pTypeAttr; 137 if ( ( (pTypeAttr = pElem->findAttribute("xsi:type")))138 || ( (pTypeAttr = pElem->findAttribute("type")))137 if ( (pTypeAttr = pElem->findAttribute("type", "xsi")) != NULL 138 || (pTypeAttr = pElem->findAttribute("type")) != NULL 139 139 ) 140 140 pcszTypeAttr = pTypeAttr->getValue(); … … 231 231 232 232 // optional vbox:uuid attribute (if OVF was exported by VirtualBox != 3.2) 233 pelmDisk->getAttributeValue(" vbox:uuid", d.uuidVbox);233 pelmDisk->getAttributeValue("uuid", d.uuidVbox, "vbox"); 234 234 235 235 const char *pcszFileRef; … … 335 335 // peek under the <VirtualSystem> node whether we have a <vbox:Machine> node; 336 336 // that case case, the caller can completely ignore the OVF but only load the VBox machine XML 337 vsys.pelmVboxMachine = pelmVirtualSystem->findChildElement ("vbox", "Machine");337 vsys.pelmVboxMachine = pelmVirtualSystem->findChildElementNS("vbox", "Machine"); 338 338 339 339 // now look for real OVF … … 351 351 { 352 352 const xml::AttributeNode *pTypeAttr; 353 if ( ( (pTypeAttr = pelmThis->findAttribute("type")))354 || ( (pTypeAttr = pelmThis->findAttribute("xsi:type")))353 if ( (pTypeAttr = pelmThis->findAttribute("type")) != NULL 354 || (pTypeAttr = pelmThis->findAttribute("type", "xsi")) != NULL 355 355 ) 356 356 pcszTypeAttr = pTypeAttr->getValue(); … … 813 813 814 814 const xml::ElementNode *pelmVBoxOSType; 815 if ((pelmVBoxOSType = pelmThis->findChildElement ("vbox", // namespace816 "OSType"))) // element name815 if ((pelmVBoxOSType = pelmThis->findChildElementNS("vbox", // namespace 816 "OSType"))) // element name 817 817 vsys.strTypeVbox = pelmVBoxOSType->getValue(); 818 818 } -
trunk/src/VBox/Runtime/common/zip/xarvfs.cpp
r48868 r49028 1926 1926 xml::ElementNode const *pTocElem = NULL; 1927 1927 if (pRootElem && pRootElem->nameEquals("xar")) 1928 pTocElem = pRootElem ? pRootElem->findChildElement( NULL,"toc") : NULL;1928 pTocElem = pRootElem ? pRootElem->findChildElement("toc") : NULL; 1929 1929 if (pTocElem) 1930 1930 { -
trunk/src/VBox/Runtime/r3/xml.cpp
r48935 r49028 484 484 * @return 485 485 */ 486 bool Node::nameEquals (const char *pcszNamespace, const char *pcsz) const486 bool Node::nameEqualsNS(const char *pcszNamespace, const char *pcsz) const 487 487 { 488 488 if (m_pcszName == pcsz) … … 508 508 * Variant of nameEquals that checks the namespace as well. 509 509 * 510 * @return true if equal, false if not. 511 * @param pcszNamespace The name space prefix or NULL. 510 * @returns true if equal, false if not. 512 511 * @param pcsz The element name. 513 512 * @param cchMax The maximum number of character from @a pcsz to 514 513 * match. 515 */ 516 bool Node::nameEqualsN(const char *pcszNamespace, const char *pcsz, size_t cchMax) const 514 * @param pcszNamespace The name space prefix or NULL (default). 515 */ 516 bool Node::nameEqualsN(const char *pcsz, size_t cchMax, const char *pcszNamespace /* = NULL*/) const 517 517 { 518 518 /* Match the name. */ … … 793 793 * @return 794 794 */ 795 const ElementNode *ElementNode::findChildElement (const char *pcszNamespace, const char *pcszMatch) const795 const ElementNode *ElementNode::findChildElementNS(const char *pcszNamespace, const char *pcszMatch) const 796 796 { 797 797 Node *p; … … 801 801 { 802 802 ElementNode *pelm = static_cast<ElementNode*>(p); 803 if (pelm->nameEquals (pcszNamespace, pcszMatch))803 if (pelm->nameEqualsNS(pcszNamespace, pcszMatch)) 804 804 return pelm; 805 805 } … … 834 834 size_t cchThis = strchr(pcszPath, '/') - pcszPath; 835 835 if (cchThis == (size_t)((const char *)0 - pcszPath)) 836 return this->findChildElement(pcszNamespace, pcszPath);836 return findChildElementNS(pcszNamespace, pcszPath); 837 837 838 838 /** @todo Can be done without recursion as we have both sibling lists and parent … … 844 844 { 845 845 const ElementNode *pElm = static_cast<const ElementNode *>(p); 846 if (pElm->nameEqualsN(pcsz Namespace, pcszPath, cchThis))846 if (pElm->nameEqualsN(pcszPath, cchThis, pcszNamespace)) 847 847 { 848 848 pElm = findChildElementP(pcszPath + cchThis, pcszNamespace); … … 921 921 { 922 922 const ElementNode *pElem = static_cast<const ElementNode *>(pSibling); 923 if (pElem->nameEquals (pcszNamespace, pcszMatch))923 if (pElem->nameEqualsNS(pcszNamespace, pcszMatch)) 924 924 return pElem; 925 925 } … … 940 940 { 941 941 const ElementNode *pElem = static_cast<const ElementNode *>(pSibling); 942 if (pElem->nameEquals (pcszNamespace, pcszMatch))942 if (pElem->nameEqualsNS(pcszNamespace, pcszMatch)) 943 943 return pElem; 944 944 } … … 950 950 * Looks up the given attribute node in this element's attribute map. 951 951 * 952 * With respect to namespaces, the internal attributes map stores namespace 953 * prefixes with attribute names only if the attribute uses a non-default 954 * namespace. As a result, the following rules apply: 955 * 956 * -- To find attributes from a non-default namespace, pcszMatch must not 957 * be prefixed with a namespace. 958 * 959 * -- To find attributes from the default namespace (or if the document does 960 * not use namespaces), pcszMatch must be prefixed with the namespace 961 * prefix and a colon. 962 * 963 * For example, if the document uses the "vbox:" namespace by default, you 964 * must omit "vbox:" from pcszMatch to find such attributes, whether they 965 * are specifed in the xml or not. 966 * 967 * @param pcszMatch 968 * @return 969 */ 970 const AttributeNode *ElementNode::findAttribute(const char *pcszMatch) const 952 * @param pcszMatch The name of the attribute to find. 953 * @param pcszNamespace The attribute name space prefix or NULL. 954 */ 955 const AttributeNode *ElementNode::findAttribute(const char *pcszMatch, const char *pcszNamespace /*= NULL*/) const 971 956 { 972 957 AttributeNode *p; 973 958 RTListForEachCpp(&m_attributes, p, AttributeNode, m_listEntry) 974 959 { 975 if (p->nameEquals (pcszMatch))960 if (p->nameEqualsNS(pcszNamespace, pcszMatch)) 976 961 return p; 977 962 } … … 983 968 * name and returns its value as a string. 984 969 * 985 * @param pcszMatch Name of attribute to find (see findAttribute() for986 * namespace remarks).987 * @param p pcsz Where to return the attribute.970 * @param pcszMatch Name of attribute to find. 971 * @param ppcsz Where to return the attribute. 972 * @param pcszNamespace The attribute name space prefix or NULL. 988 973 * @returns Boolean success indicator. 989 974 */ 990 bool ElementNode::getAttributeValue(const char *pcszMatch, const char **ppcsz ) const991 { 992 const AttributeNode *pAttr = findAttribute(pcszMatch );975 bool ElementNode::getAttributeValue(const char *pcszMatch, const char **ppcsz, const char *pcszNamespace /*= NULL*/) const 976 { 977 const AttributeNode *pAttr = findAttribute(pcszMatch, pcszNamespace); 993 978 if (pAttr) 994 979 { … … 1003 988 * name and returns its value as a string. 1004 989 * 1005 * @param pcszMatch Name of attribute to find (see findAttribute() for1006 * namespace remarks).1007 * @param rStr Reference to the string object that should receive the1008 * attribute value.990 * @param pcszMatch Name of attribute to find. 991 * @param pStr Pointer to the string object that should receive the 992 * attribute value. 993 * @param pcszNamespace The attribute name space prefix or NULL. 1009 994 * @returns Boolean success indicator. 1010 995 * 1011 996 * @throws Whatever the string class may throw on assignment. 1012 997 */ 1013 bool ElementNode::getAttributeValue(const char *pcszMatch, RTCString &rStr) const1014 { 1015 const AttributeNode *pAttr = findAttribute(pcszMatch );998 bool ElementNode::getAttributeValue(const char *pcszMatch, RTCString *pStr, const char *pcszNamespace /*= NULL*/) const 999 { 1000 const AttributeNode *pAttr = findAttribute(pcszMatch, pcszNamespace); 1016 1001 if (pAttr) 1017 1002 { 1018 rStr = pAttr->getValue();1003 *pStr = pAttr->getValue(); 1019 1004 return true; 1020 1005 } … … 1026 1011 * Like getAttributeValue (ministring variant), but makes sure that all backslashes 1027 1012 * are converted to forward slashes. 1028 * @param pcszMatch 1029 * @param str 1030 * @return 1031 */ 1032 bool ElementNode::getAttributeValuePath(const char *pcszMatch, RTCString &str) const 1033 { 1034 if (getAttributeValue(pcszMatch, str)) 1035 { 1036 str.findReplace('\\', '/'); 1013 * 1014 * @param pcszMatch Name of attribute to find. 1015 * @param pStr Pointer to the string object that should 1016 * receive the attribute path value. 1017 * @param pcszNamespace The attribute name space prefix or NULL. 1018 * @returns Boolean success indicator. 1019 */ 1020 bool ElementNode::getAttributeValuePath(const char *pcszMatch, RTCString *pStr, const char *pcszNamespace /*= NULL*/) const 1021 { 1022 if (getAttributeValue(pcszMatch, pStr, pcszNamespace)) 1023 { 1024 pStr->findReplace('\\', '/'); 1037 1025 return true; 1038 1026 } … … 1043 1031 /** 1044 1032 * Convenience method which attempts to find the attribute with the given 1045 * name and returns its value as a signed integer. This calls1046 * RTStrToInt32Ex internally and will only output the integer if that1047 * function returns no error.1048 * 1049 * @param pcszMatch name of attribute to find (see findAttribute() for namespace remarks)1050 * @ param i out: attribute value; overwritten only if attribute was found1051 * @return TRUE if attribute was found and str was thus updated.1052 */ 1053 bool ElementNode::getAttributeValue(const char *pcszMatch, int32_t &i) const 1054 { 1055 const char *pcsz;1056 if ( (getAttributeValue(pcszMatch, pcsz))1057 && (VINF_SUCCESS == RTStrToInt32Ex(pcsz, NULL, 0, &i))1058 )1059 return true;1060 1033 * name and returns its value as a signed 32-bit integer. 1034 * 1035 * @param pcszMatch Name of attribute to find. 1036 * @param piValue Where to return the value. 1037 * @param pcszNamespace The attribute name space prefix or NULL. 1038 * @returns Boolean success indicator. 1039 */ 1040 bool ElementNode::getAttributeValue(const char *pcszMatch, int32_t *piValue, const char *pcszNamespace /*= NULL*/) const 1041 { 1042 const char *pcsz = findAttributeValue(pcszMatch, pcszNamespace); 1043 if (pcsz) 1044 { 1045 int rc = RTStrToInt32Ex(pcsz, NULL, 0, piValue); 1046 if (rc == VINF_SUCCESS) 1047 return true; 1048 } 1061 1049 return false; 1062 1050 } … … 1064 1052 /** 1065 1053 * Convenience method which attempts to find the attribute with the given 1066 * name and returns its value as an unsigned integer.This calls1067 * RTStrToUInt32Ex internally and will only output the integer if that1068 * function returns no error.1069 * 1070 * @param pcszMatch name of attribute to find (see findAttribute() for namespace remarks)1071 * @ param i out: attribute value; overwritten only if attribute was found1072 * @return TRUE if attribute was found and str was thus updated.1073 */ 1074 bool ElementNode::getAttributeValue(const char *pcszMatch, uint32_t &i) const 1075 { 1076 const char *pcsz;1077 if ( (getAttributeValue(pcszMatch, pcsz))1078 && (VINF_SUCCESS == RTStrToUInt32Ex(pcsz, NULL, 0, &i))1079 )1080 return true;1081 1054 * name and returns its value as an unsigned 32-bit integer. 1055 * 1056 * @param pcszMatch Name of attribute to find. 1057 * @param puValue Where to return the value. 1058 * @param pcszNamespace The attribute name space prefix or NULL. 1059 * @returns Boolean success indicator. 1060 */ 1061 bool ElementNode::getAttributeValue(const char *pcszMatch, uint32_t *puValue, const char *pcszNamespace /*= NULL*/) const 1062 { 1063 const char *pcsz = findAttributeValue(pcszMatch, pcszNamespace); 1064 if (pcsz) 1065 { 1066 int rc = RTStrToUInt32Ex(pcsz, NULL, 0, puValue); 1067 if (rc == VINF_SUCCESS) 1068 return true; 1069 } 1082 1070 return false; 1083 1071 } … … 1085 1073 /** 1086 1074 * Convenience method which attempts to find the attribute with the given 1087 * name and returns its value as a signed long integer. This calls 1088 * RTStrToInt64Ex internally and will only output the integer if that 1089 * function returns no error. 1090 * 1091 * @param pcszMatch Name of attribute to find (see findAttribute() for 1092 * namespace remarks). 1093 * @param i Where to return the attribute value on success. 1075 * name and returns its value as a signed 64-bit integer. 1076 * 1077 * @param pcszMatch Name of attribute to find. 1078 * @param piValue Where to return the value. 1079 * @param pcszNamespace The attribute name space prefix or NULL. 1094 1080 * @returns Boolean success indicator. 1095 1081 */ 1096 bool ElementNode::getAttributeValue(const char *pcszMatch, int64_t *piValue ) const1097 { 1098 const char *pcsz = findAttributeValue(pcszMatch );1082 bool ElementNode::getAttributeValue(const char *pcszMatch, int64_t *piValue, const char *pcszNamespace /*= NULL*/) const 1083 { 1084 const char *pcsz = findAttributeValue(pcszMatch, pcszNamespace); 1099 1085 if (pcsz) 1100 1086 { … … 1108 1094 /** 1109 1095 * Convenience method which attempts to find the attribute with the given 1110 * name and returns its value as an unsigned long integer.This calls1111 * RTStrToUInt64Ex internally and will only output the integer if that1112 * function returns no error.1113 * 1114 * @param pcszMatch name of attribute to find (see findAttribute() for namespace remarks)1115 * @ param i out: attribute value; overwritten only if attribute was found1116 * @return TRUE if attribute was found and str was thus updated.1117 */ 1118 bool ElementNode::getAttributeValue(const char *pcszMatch, uint64_t &i) const 1119 { 1120 const char *pcsz;1121 if ( (getAttributeValue(pcszMatch, pcsz))1122 && (VINF_SUCCESS == RTStrToUInt64Ex(pcsz, NULL, 0, &i))1123 )1124 return true;1125 1096 * name and returns its value as an unsigned 64-bit integer. 1097 * 1098 * @param pcszMatch Name of attribute to find. 1099 * @param puValue Where to return the value. 1100 * @param pcszNamespace The attribute name space prefix or NULL. 1101 * @returns Boolean success indicator. 1102 */ 1103 bool ElementNode::getAttributeValue(const char *pcszMatch, uint64_t *puValue, const char *pcszNamespace /*= NULL*/) const 1104 { 1105 const char *pcsz = findAttributeValue(pcszMatch, pcszNamespace); 1106 if (pcsz) 1107 { 1108 int rc = RTStrToUInt64Ex(pcsz, NULL, 0, puValue); 1109 if (rc == VINF_SUCCESS) 1110 return true; 1111 } 1126 1112 return false; 1127 1113 } … … 1132 1118 * "yes", "no", "1" or "0" as valid values. 1133 1119 * 1134 * @param pcszMatch name of attribute to find (see findAttribute() for namespace remarks) 1135 * @param f out: attribute value; overwritten only if attribute was found 1136 * @return TRUE if attribute was found and str was thus updated. 1137 */ 1138 bool ElementNode::getAttributeValue(const char *pcszMatch, bool &f) const 1139 { 1140 const char *pcsz; 1141 if (getAttributeValue(pcszMatch, pcsz)) 1120 * @param pcszMatch Name of attribute to find. 1121 * @param pfValue Where to return the value. 1122 * @param pcszNamespace The attribute name space prefix or NULL. 1123 * @returns Boolean success indicator. 1124 */ 1125 bool ElementNode::getAttributeValue(const char *pcszMatch, bool *pfValue, const char *pcszNamespace /*= NULL*/) const 1126 { 1127 const char *pcsz = findAttributeValue(pcszMatch, pcszNamespace); 1128 if (pcsz) 1142 1129 { 1143 1130 if ( !strcmp(pcsz, "true") … … 1146 1133 ) 1147 1134 { 1148 f= true;1135 *pfValue = true; 1149 1136 return true; 1150 1137 } … … 1154 1141 ) 1155 1142 { 1156 f= false;1143 *pfValue = false; 1157 1144 return true; 1158 1145 } … … 1483 1470 m_pcszNamespacePrefix = (const char *)pLibAttr->ns->prefix; 1484 1471 m_pcszNamespaceHref = (const char *)pLibAttr->ns->href; 1485 1486 if ( !pElmRoot->m_pcszNamespaceHref1487 || strcmp(m_pcszNamespaceHref, pElmRoot->m_pcszNamespaceHref))1488 {1489 // not default namespace:1490 m_strKey = m_pcszNamespacePrefix;1491 m_strKey.append(':');1492 m_strKey.append(m_pcszName);1493 }1494 1472 } 1495 1473 }
Note:
See TracChangeset
for help on using the changeset viewer.