We are going to parse the sample xml shown alongside to create an instance 'xml_smaple' of an xml object object xml_sample=samplexml(file) No Errors : xml parsed properly 'xml_sample' created xml_sample(_name) : SampleXml xml_sample(_node(00)) : 03 xml_sample(_attribute(01)) : Auther xml_sample(_attribute(Auther)) : "kdv" Date xml_sample(Date(_attribute(value))) :Tue June 8, 2004 xml_sample(Quote.Headline) : This is the headline xml_sample(_node)="Quote" xml_sample(Headline) :This is the headline xml_sample(Quote.Headline) : xml_sample(_root.Quote.Headline) : This is the headline xml_sample(_root.Date._attribute(value)) : Tue June 8, 2004 Reading multiple nodes having the same tag xml_sample(body.p(00)): 04 xml_sample(body.p): Following is a notable quote from history. "Great Russia is rising from her knees." -- Boris Yeltsin on his inauguration as Russia's first elected president on July 10, 1991. xml_sample(body.p(01)) : Following is a notable quote from history. xml_sample(body.p(02)) : xml_sample(body.p(03)) : "Great Russia is rising from her knees." xml_sample(body.p(04)) : -- Boris Yeltsin on his inauguration as Russia's first elected president on July 10, 1991. xml_sample(_node)="body.p" loop xloop (xml_sample(_root.Quote.body.p(00))) xloop(count); xml_sample(_node); xml_sample(_node)="_next" repeat xloop 01 Following is a notable quote from history. 02 03 "Great Russia is rising from her knees." 04 -- Boris Yeltsin on his inauguration as Russia's first elected president on July 10, 1991. xml_sample(_previous._previous.Headline) : xml_sample(_root.Quote.body) : Following is a notable quote from history.
"Great Russia is rising from her knees." -- Boris Yeltsin on his inauguration as Russia's first elected president on July 10, 1991. xml_sample(_node)="_root.Quote"; // go to the required node xml_sample(MyNewNode)="";//To make a node, assign empty string using the required tag xml_sample(_node)="MyNewNode";// go to this node xml_sample(_attribute.PS)="This node was added by "caravan""; // adding attribute 'PS' xml_sample(MyComment)="No Comment";// add a new property here You can see the new node in the XML generated at right This was added to the existing xml object xyz This is used to generate XML from scratch Finally go to the root and generate the xml by: |
Generate XML output : xml_sample(); <Date value="Tue June 8, 2004"/> <Quote> <Headline>This is the headline</Headline> <body> <p> Following is a notable quote from history.</p> <p> </p> <p> "Great Russia is rising from her knees."</p> <p> -- Boris Yeltsin on his inauguration as Russia's first elected president on July 10, 1991. </p> </body> <MyNewNode PS="This node was added by "caravan""> <MyComment>No Comment</MyComment> </MyNewNode> </Quote> <credit>Reuters News Agency</credit> </SampleXml> |