Subject: Error in "InnerXml" parsing for contents with only 1 level of tags
There is a problem with InnerXml property : it can't handle single tagged content : for exemple "<foo>some text</foo>" won't work and will be parsed as "<foo />". But more complex content will be ok : "<foo><bar>Some text</bar></foo>" will be parsed correctly.
An exemple to reproduce the bug :
To make it work, I modified the agsXMPP.Xml.StreamParser.AddText(string text) method (I added the violet part) :
I's a quick and dirty hack, I don't know if it's the correct way to handle that case.
An exemple to reproduce the bug :
using System;
using agsXMPP.protocol.client;
using agsXMPP;
namespace AgsXmppBugReport
{
class Program
{
static void Main(string[] args)
{
Message m = new Message(new Jid("SomeId"))
{
Id = "MessageIdentifier",
From = new Jid("SomeOtherId")
};
string customContent = "<someTag>Some content</someTag>";
m.InnerXml = customContent;
Console.WriteLine(m.ToString());
//--> result KO : the text between the tag "someTag" wasn't correctly parsed :
//<message xmlns="jabber:client" to="SomeId" id="MessageIdentifier" from="SomeOtherId"><someTag /></message>
string customContent2 = "<someTag><someOtherTag>Some content</someOtherTag></someTag>";
m.InnerXml = customContent2;
Console.WriteLine(m.ToString());
//--> result OK : the xml string customContent2 was entirely parsed.
//<message xmlns="jabber:client" to="SomeId" id="MessageIdentifier" from="SomeOtherId"><someTag><someOtherTag>Some content</someOtherTag></someTag></message>
Console.Read();
}
}
}
using agsXMPP.protocol.client;
using agsXMPP;
namespace AgsXmppBugReport
{
class Program
{
static void Main(string[] args)
{
Message m = new Message(new Jid("SomeId"))
{
Id = "MessageIdentifier",
From = new Jid("SomeOtherId")
};
string customContent = "<someTag>Some content</someTag>";
m.InnerXml = customContent;
Console.WriteLine(m.ToString());
//--> result KO : the text between the tag "someTag" wasn't correctly parsed :
//<message xmlns="jabber:client" to="SomeId" id="MessageIdentifier" from="SomeOtherId"><someTag /></message>
string customContent2 = "<someTag><someOtherTag>Some content</someOtherTag></someTag>";
m.InnerXml = customContent2;
Console.WriteLine(m.ToString());
//--> result OK : the xml string customContent2 was entirely parsed.
//<message xmlns="jabber:client" to="SomeId" id="MessageIdentifier" from="SomeOtherId"><someTag><someOtherTag>Some content</someOtherTag></someTag></message>
Console.Read();
}
}
}
To make it work, I modified the agsXMPP.Xml.StreamParser.AddText(string text) method (I added the violet part) :
private void AddText(string text)
{
if (text == "")
return;
//Console.WriteLine("AddText:" + text);
//Console.WriteLine(lastTOK);
if (current != null)
{
if (m_cdata)
{
Node last = current.LastNode;
if (last != null && last.NodeType == NodeType.Cdata)
last.Value = last.Value + text;
else
current.AddChild(new CData(text));
}
else
{
Node last = current.LastNode;
if (last != null && last.NodeType == NodeType.Text)
last.Value = last.Value + text;
else
current.AddChild(new Text(text));
}
}
{
if (text == "")
return;
//Console.WriteLine("AddText:" + text);
//Console.WriteLine(lastTOK);
if (current != null)
{
if (m_cdata)
{
Node last = current.LastNode;
if (last != null && last.NodeType == NodeType.Cdata)
last.Value = last.Value + text;
else
current.AddChild(new CData(text));
}
else
{
Node last = current.LastNode;
if (last != null && last.NodeType == NodeType.Text)
last.Value = last.Value + text;
else
current.AddChild(new Text(text));
}
}
else
{
string s = text.Trim();
if (!string.IsNullOrEmpty(s))
{
Node last = ((Element)m_root).LastNode;
if (m_cdata)
{
if (last != null && last.NodeType == NodeType.Cdata)
last.Value = last.Value + text;
else
m_root.AddChild(new CData(text));
} else
{
if (last != null && last.NodeType == NodeType.Text)
last.Value = last.Value + text;
else
m_root.AddChild(new Text(text));
}
}
}
{
string s = text.Trim();
if (!string.IsNullOrEmpty(s))
{
Node last = ((Element)m_root).LastNode;
if (m_cdata)
{
if (last != null && last.NodeType == NodeType.Cdata)
last.Value = last.Value + text;
else
m_root.AddChild(new CData(text));
} else
{
if (last != null && last.NodeType == NodeType.Text)
last.Value = last.Value + text;
else
m_root.AddChild(new Text(text));
}
}
}
}
I's a quick and dirty hack, I don't know if it's the correct way to handle that case.
artiche
Show profile
Link to this post
