|
Экспорт объекта в XML с %XML.Adaptor
|
|||
---|---|---|---|
#18+
Есть класс VCD.ovf.RASDType, наследующийся от %XML.Adaptor. Когда экспортирую экземпляр этого класса (RAM) в XML, выполняю: set attrs=2 set attrs(1)="xmlns" set attrs(1,0)=" http://www.vmware.com/vcloud/v1.5" set attrs(2)="xmlns:rasd" set attrs(2,0)=" http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" do RAM.XMLExportToString(.rString,"Item",,,.attrs) И rString получается<Item xmlns=" http://www.vmware.com/vcloud/v1.5" xmlns:rasd=" http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" > <AllocationUnits>byte * 2^20</AllocationUnits> <Description>Memory Size</Description> <ElementName>512 MB of memory</ElementName> <InstanceID>5</InstanceID> <Reservation>0</Reservation> <ResourceType>4</ResourceType> <VirtualQuantity>1024</VirtualQuantity> <Weight>0</Weight> <Link rel="edit" type="application/vnd.vmware.vcloud.rasdItem+xml" href=" https://vcd.com/api/vApp/vmid/virtualHardwareSection/memory" /> </Item>А надо на выходе получить:<Item xmlns=" http://www.vmware.com/vcloud/v1.5" xmlns:rasd=" http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" > <rasd:AllocationUnits>byte * 2^20</rasd:AllocationUnits> <rasd:Description>Memory Size</rasd:Description> <rasd:ElementName>512 MB of memory</rasd:ElementName> <rasd:InstanceID>5</rasd:InstanceID> <rasd:Reservation>0</rasd:Reservation> <rasd:ResourceType>4</rasd:ResourceType> <rasd:VirtualQuantity>512</rasd:VirtualQuantity> <rasd:Weight>0</rasd:Weight> <Link rel="edit" type="application/vnd.vmware.vcloud.rasdItem+xml" href=" https://vcd.com/api/vApp/vmid/virtualHardwareSection/memory" /> </Item> Т.е., чтобы к элементам в корне добавился namespace rasd. Варианта с приводом rString к нужной форме хотелось бы избежать. Что можно сделать? ... |
|||
:
Нравится:
Не нравится:
|
|||
03.07.2014, 05:01 |
|
Экспорт объекта в XML с %XML.Adaptor
|
|||
---|---|---|---|
#18+
Я добавляю к полям аттрибут XMLNAME, типа такого:Property InsideH As Word.TableBorder(XMLNAME = "w:insideH"); ... |
|||
:
Нравится:
Не нравится:
|
|||
03.07.2014, 05:32 |
|
Экспорт объекта в XML с %XML.Adaptor
|
|||
---|---|---|---|
#18+
Блок А.Н., Спасибо, но не могу редактировать VCD.ovf.RASDType - используется много где, а XMLNAME уже задано. ... |
|||
:
Нравится:
Не нравится:
|
|||
03.07.2014, 05:36 |
|
Экспорт объекта в XML с %XML.Adaptor
|
|||
---|---|---|---|
#18+
Вам один и тот же объект в разные форматы XML нужно выгружать? ... |
|||
:
Нравится:
Не нравится:
|
|||
03.07.2014, 09:51 |
|
Экспорт объекта в XML с %XML.Adaptor
|
|||
---|---|---|---|
#18+
eduard93Что можно сделать?Использовать %XML.Writer , как это советует документация:Документация/// The XMLExport method does not directly support many of the XML parameters. /// If you want control of the format of the export, you need to use the %XML.Writer class.<p>Например s ns1=" http://www.vmware.com/vcloud/v1.5" s ns2=" http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" s w=##class(%XML.Writer).%New() s w.Indent=1 s w.NoXMLDeclaration=1 s w.DefaultXmlns=ns1 d w.AddNamespace(ns2,"rasd") d w.OutputToString() d w.RootObject(ARM,"Item",ns2) s rString=w.GetXMLString() w rString ... |
|||
:
Нравится:
Не нравится:
|
|||
03.07.2014, 13:29 |
|
Экспорт объекта в XML с %XML.Adaptor
|
|||
---|---|---|---|
#18+
servit, спасибо, выдаёт:<s01:Item xmlns=" http://www.vmware.com/vcloud/v1.5" xmlns:rasd=" http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" xmlns:s01=" http://schemas.dmtf.org/ovf/envelope/1" > <rasd:AllocationUnits xmlns:s02=" http://schemas.dmtf.org/wbem/wscim/1/common" >byte * 2^20</rasd:AllocationUnits> <rasd:Description xmlns:s02=" http://schemas.dmtf.org/wbem/wscim/1/common" >Memory Size</rasd:Description> <rasd:ElementName xmlns:s02=" http://schemas.dmtf.org/wbem/wscim/1/common" >1024 MB of memory</rasd:ElementName> <rasd:InstanceID xmlns:s02=" http://schemas.dmtf.org/wbem/wscim/1/common" >5</rasd:InstanceID> <rasd:Reservation xmlns:s02=" http://schemas.dmtf.org/wbem/wscim/1/common" >0</rasd:Reservation> <rasd:ResourceType>4</rasd:ResourceType> <rasd:VirtualQuantity xmlns:s02=" http://schemas.dmtf.org/wbem/wscim/1/common" >2</rasd:VirtualQuantity> <rasd:Weight xmlns:s02=" http://schemas.dmtf.org/wbem/wscim/1/common" >0</rasd:Weight> <Link rel="edit" type="application/vnd.vmware.vcloud.rasdItem+xml" href=" https://vcd.com/api/vApp/vmid/virtualHardwareSection/memory" /> </s01:Item> Как избавиться от s01,s02? Интересует в основном, как убрать s01 из s01:Item. В %XML.Writer нашел свойство SuppressAutoPrefix, но оно [ Internal, Private ] и никаких общедоступных сеттеров. ... |
|||
:
Нравится:
Не нравится:
|
|||
04.07.2014, 06:12 |
|
Экспорт объекта в XML с %XML.Adaptor
|
|||
---|---|---|---|
#18+
eduard93Интересует в основном, как убрать s01 из s01:Item.Самое простое - $replace или вручнуюClass demo.test Extends %RegisteredObject { Property AllocationUnits As %VarString; Property Description As %VarString; Property ElementName As %VarString; Property InstanceID As %TinyInt; Property Reservation As %TinyInt; Property ResourceType As %TinyInt; Property VirtualQuantity As %TinyInt; Property Weight As %TinyInt; ClassMethod Test() { s ns1=" http://www.vmware.com/vcloud/v1.5" s ns2=" http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" s ns3=" http://schemas.dmtf.org/ovf/envelope/1" s ARM=..%New() s ARM.AllocationUnits="byte * 2^20" s ARM.Description="Memory Size" s ARM.ElementName="1024 MB of memory" s ARM.InstanceID=5 s ARM.Reservation=0 s ARM.ResourceType=4 s ARM.VirtualQuantity=2 s ARM.Weight=0 s w=##class(%XML.Writer).%New() s w.Indent=$$$YES s w.NoXMLDeclaration=$$$YES d w.AddNamespace(ns2,"rasd") d w.AddNamespace(ns3) d w.OutputToString() d w.StartDocument() d w.RootElement("Item",ns1) s w.DefaultXmlns=ns1 d w.Element("AllocationUnits",ns2) d w.WriteChars(ARM.AllocationUnits) d w.EndElement() d w.Element("Description",ns2) d w.WriteChars(ARM.Description) d w.EndElement() d w.Element("ElementName",ns2) d w.WriteChars(ARM.ElementName) d w.EndElement() d w.Element("InstanceID",ns2) d w.WriteChars(ARM.InstanceID) d w.EndElement() d w.Element("Reservation",ns2) d w.WriteChars(ARM.Reservation) d w.EndElement() d w.Element("ResourceType",ns2) d w.WriteChars(ARM.ResourceType) d w.EndElement() d w.Element("VirtualQuantity",ns2) d w.WriteChars(ARM.VirtualQuantity) d w.EndElement() d w.Element("Weight",ns2) d w.WriteChars(ARM.Weight) d w.EndElement() d w.Element("Link") d w.WriteAttribute("rel","edit") d w.WriteAttribute("type","application/vnd.vmware.vcloud.rasdItem+xml") d w.WriteAttribute("href"," https://vcd.com/api/vApp/vmid/virtualHardwareSection/memory" ) d w.EndElement() d w.EndRootElement() d w.EndDocument() s rString=w.GetXMLString() w rString } }Результат Код: plaintext 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11.
... |
|||
:
Нравится:
Не нравится:
|
|||
04.07.2014, 11:12 |
|
Экспорт объекта в XML с %XML.Adaptor
|
|||
---|---|---|---|
#18+
servitПокажите Ваш код. s ns1=" http://www.vmware.com/vcloud/v1.5" s ns2=" http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" s w=##class(%XML.Writer).%New() s w.Indent=1 s w.NoXMLDeclaration=1 s w.DefaultXmlns=ns1 d w.AddNamespace(ns2,"rasd") s w.DefaultNamespace="" d w.OutputToString() d w.RootObject(RAM,"Item",ns2) s str1=w.GetXMLString() w str1 А в классе VCD.ovf.RASDType свойства такие:Property AllocationUnits As VCD.cim.cimString(REFELEMENTQUALIFIED = 1, REFNAMESPACE = " http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" , XMLNAME = "AllocationUnits", XMLREF = 1); Класс VCD.cim.cimString:Class VCD.cim.cimString Extends (%SerialObject, %XML.Adaptor) [ ClassType = serial, CompileAfter = , Inheritance = right, ProcedureBlock ] { Parameter ELEMENTQUALIFIED = 1; Parameter NAMESPACE = " http://schemas.dmtf.org/wbem/wscim/1/common" ; Parameter XMLNAME = "cimString"; Parameter XMLSEQUENCE = 0; Property content As %String(MAXLEN = "", XMLNAME = "content", XMLPROJECTION = "CONTENT"); } ... |
|||
:
Нравится:
Не нравится:
|
|||
05.07.2014, 00:34 |
|
Экспорт объекта в XML с %XML.Adaptor
|
|||
---|---|---|---|
#18+
eduard93 , Не увидел в последнем коде упоминания " http://schemas.dmtf.org/ovf/envelope/1". Чтобы избавиться от " http://schemas.dmtf.org/wbem/wscim/1/common" в свойствах, добавьте его через AddNamespace(), а ещё лучше создайте отдельные классы для разных форматов XML. ... |
|||
:
Нравится:
Не нравится:
|
|||
07.07.2014, 09:50 |
|
|
start [/forum/topic.php?fid=39&fpage=20&tid=1556853]: |
0ms |
get settings: |
9ms |
get forum list: |
12ms |
check forum access: |
3ms |
check topic access: |
3ms |
track hit: |
39ms |
get topic data: |
11ms |
get forum data: |
2ms |
get page messages: |
51ms |
get tp. blocked users: |
2ms |
others: | 284ms |
total: | 416ms |
0 / 0 |