EldoS | Feel safer!

Software components for data protection, secure storage and transfer

XML - Modifying schema attributes to loaded doc

Also by EldoS: MsgConnect
Cross-platform protocol-independent communication framework for building peer-to-peer and client-server applications and middleware components.
#20611
Posted: 06/25/2012 19:52:25
by Leonardo Herrera (Standard support level)
Joined: 02/14/2011
Posts: 66

Hello,

Is it possible to change namespace / schema attributes from an already loaded XML doc? I need to change
Code
<Mydoc version="1.0">
...
</Mydoc>

to
Code
<Mydoc xmlns="http://www.example.com/MyDoc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.com/MyDoc Doc_v10.xsd" version="1.0">
...
</Mydoc>

I've tried using the XmlNS property to no avail. Also tried using DocumentElement.SetAttributeNS() method but got duplicated elements.

How should be an easy way to change these to an already loaded document? (I want a workaround to this StackOverflow question: http://stackoverflow.com/questions/11182797/delphi-xml-bindings-objects-exporting-nodes)
#20612
Posted: 06/26/2012 01:20:19
by Vsevolod Ievgiienko (EldoS Corp.)

Thank you for getting in touch with us.

Next code will do the job:

Code
var D: TElXMLDOMDocument;
...
D.DocumentElement.SetAttributeNS( '', 'xmlns', 'http://www.example.com/MyDoc');
    D.DocumentElement.SetAttributeNS( '', 'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
    D.DocumentElement.SetAttributeNS( '', 'xsi:schemaLocation', 'http://www.example.com/MyDoc Doc_v10.xsd');
#20623
Posted: 06/26/2012 17:16:10
by Leonardo Herrera (Standard support level)
Joined: 02/14/2011
Posts: 66

Thank you. It kind of worked.

I got the following:

Code
<Mydoc xmlns="http://www.example.com/MyDoc" xsi="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="http://www.example.com/MyDoc Doc_v10.xsd" version="1.0">
    ...
</Mydoc>


instead of

Code
<Mydoc xmlns="http://www.example.com/MyDoc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.com/MyDoc Doc_v10.xsd" version="1.0">
    ...
</Mydoc>


Is it possible to include the namespace prefixes (xmlns, xsi) in the document element attributes?
#20629
Posted: 06/27/2012 03:31:19
by Vsevolod Ievgiienko (EldoS Corp.)

Its strange. I've just re-checked my code with both 9th and 10th version and it produces exactly what you need. Please post your XML via Helpdesk so we'll be able to reproduce the problem and find a solution.

Reply

Statistics

Topic viewed 1735 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!