I
I
Ilya Beloborodov2015-11-12 16:09:46
PHP
Ilya Beloborodov, 2015-11-12 16:09:46

How to add new element in xml?

Prompt, I receive xml in which I need to add a new element. How to do it?
getting it

<User xmlns="http://www.vmware.com/vcloud/v1.5" name="admin" id="urn:vcloud:user:3284020b-12b3-4e39-9096-9b7c0556f21b" href="https://example.com/api/admin/user/3284020b-12b3-4e39-9096-9b7c0556f21b" type="application/vnd.vmware.admin.user+xml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://example.com/api/v1.5/schema/master.xsd">
    <Link rel="edit" href="https://example.com/api/admin/user/3284020b-12b3-4e39-9096-9b7c0556f21b" type="application/vnd.vmware.admin.user+xml"/>
    <Link rel="takeOwnership" href="https://example.com/api/admin/user/3284020b-12b3-4e39-9096-9b7c0556f21b/action/takeOwnership"/>
    <FullName/>
    <EmailAddress/>
    <Telephone/>
    <IsEnabled>true</IsEnabled>
    <IsLocked>false</IsLocked>
    <IM/>
    <NameInSource>admin</NameInSource>
    <IsAlertEnabled>false</IsAlertEnabled>
    <IsExternal>false</IsExternal>
    <ProviderType>INTEGRATED</ProviderType>
    <IsDefaultCached>false</IsDefaultCached>
    <IsGroupRole>false</IsGroupRole>
    <StoredVmQuota>0</StoredVmQuota>
    <DeployedVmQuota>0</DeployedVmQuota>
    <Role href="https://example.com/api/admin/role/a08a8798-7d9b-34d6-8dad-48c7182c5f66" name="Organization Administrator" type="application/vnd.vmware.admin.role+xml"/>
    <GroupReferences/>
</User>

you need to add, <password>123456</password>
that is, in the total it should be like this
<User xmlns="http://www.vmware.com/vcloud/v1.5" name="admin" id="urn:vcloud:user:3284020b-12b3-4e39-9096-9b7c0556f21b" href="https://example.com/api/admin/user/3284020b-12b3-4e39-9096-9b7c0556f21b" type="application/vnd.vmware.admin.user+xml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://example.com/api/v1.5/schema/master.xsd">
    <Link rel="edit" href="https://example.com/api/admin/user/3284020b-12b3-4e39-9096-9b7c0556f21b" type="application/vnd.vmware.admin.user+xml"/>
    <Link rel="takeOwnership" href="https://example.com/api/admin/user/3284020b-12b3-4e39-9096-9b7c0556f21b/action/takeOwnership"/>
    <password>123456</password>
    <FullName/>
    <EmailAddress/>
    <Telephone/>
    <IsEnabled>true</IsEnabled>
    <IsLocked>false</IsLocked>
    <IM/>
    <NameInSource>admin</NameInSource>
    <IsAlertEnabled>false</IsAlertEnabled>
    <IsExternal>false</IsExternal>
    <ProviderType>INTEGRATED</ProviderType>
    <IsDefaultCached>false</IsDefaultCached>
    <IsGroupRole>false</IsGroupRole>
    <StoredVmQuota>0</StoredVmQuota>
    <DeployedVmQuota>0</DeployedVmQuota>
    <Role href="https://example.com/api/admin/role/a08a8798-7d9b-34d6-8dad-48c7182c5f66" name="Organization Administrator" type="application/vnd.vmware.admin.role+xml"/>
    <GroupReferences/>
</User>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
riot26, 2015-11-12
@riot26

String concatenation, obviously. Show what you get and what you need to add.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question