Load and save methods usage examples
Load and save method usage examples for the xml.DomDocument
class.
You can load an existing XML document. Before loading an XML document you need to create the DomDocument object.
A DomDocument can load files using different URI: http://,
https://, tcp://, tcps://,
file:// and alias://.
See getErrorsCount() and getErrorDescription()
to retrieve error messages related to XML document.
load("data.xml")
load("http://www.w3schools.com/xml/cd_catalog.xml")
load("https://localhost:6394/ws/r/calculator?WSDL")
load("file:///data/cd_catalog.xml")
load("tcp://localhost:4242/")
load("tcps://localhost:4243/")
load("alias://demo")
In
the example the demo alias is defined in fglprofile as
ws.demo.url = "http://www.w3schools.com/xml/cd_catalog.xml"loadfromstring("<List> <elt>First element</elt>
<elt>Second element</elt> <elt>Third element</elt> </List>")The
example, produces a subtree with a root node List and three nodes
elt and three textnode.DomDocument can be saved at different URI beginning with:
http://, https://, tcp://,
tcps://, file:// and alias://.
save("myfile.xml")
save("http://myserver:8080/data/save1.xml")
save("file:///data/save.xml")
save("tcp://localhost:4242/")
save("alias://test")In
the example the test alias is defined in fglprofile as
ws.test.url = "http://localhost:8080/data/save3.xml"The saveToString method saves the DomDocument in a string.
See getErrorsCount() and getErrorDescription()
to retrieve error messages related to XML document.
The normalize function emulates a DomDocument save and load. It
can be called at any stage of the DomDocument building. This removes empty Text
nodes and sets namespace declarations as if the document had been saved.