Appending string in NSXMLNode
When I call the method setStringValue: mCurrentString
when </Text>
is encountered, the child elements which are already attached to the element are detached. Can any one suggest why it is happening so.
The sample XML file goes like this:
<?xml version="1.0" encoding="UTF-8"?>
<Test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Version="1.0">
<Page Id="123-234-345-456-567">
<Word/>
<Text Id="234-345-456-567-678" Left="120.789" Top="120.234657" Width="300.2390" Height="50.00">
<Content>
<![CDATA[<FlowDocument FontFamily="Helvetica" FontSize="24" Foreground="#FFFFFF00" TextAlignment="Left" PagePadding="5,0,5,0" AllowDrop="True" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"><Paragraph><Run FontFamily="Helvetica" FontSize="24" Foreground="FF00B38D" xml:lang="en-gb">This is for Testing purpose</Run></Paragraph>]]></Content>
<Stroke Color="#FF00B300" Width="10"/>
</Text>
<Image Id="345-456-567-678-789" Left="200.345" Top="350.678" Width="200.00" Height="200.00">
<Source>Bear.png</Source>
</Image>
</Page>
<Page Id="345-897-123-756-098" Left="100.90" Top="200.098" Width="200.098" Height="50.09">
&开发者_高级运维lt;Image Id="756-098-978-685-298" Left="12098" Top="340.87" Right="109.78" Height="100.987">
<Source>Flower.png</Source>
</Image>
</Page>
</Test>
This is the method i am using for an NSXMLElement object:
// mCurrentString is the string that obtained through delegate method.
[mCurrentElement setStringValue: mCurrentString];
Method setString will replace the element contents with the specified string value.
To append a text node to an element that already has child nodes, create a node of kind NSXMLTextKind
and then append it to the element with method addChild.
NSXMLElement *element;
NSXMLNode *node = [[NSXMLNode alloc] initWithKind: NSXMLTextKind];
[node setStringValue: @"lorem ipsum"];
[element addChild: node];
精彩评论