Bug 2170 - AnimationInterface outputs improperly formed XML

This commit is contained in:
miilic
2015-10-01 07:59:09 -07:00
parent 5aa0f567df
commit 79106b45f2
6 changed files with 49 additions and 16 deletions

View File

@@ -235,7 +235,7 @@ With the above statement, AnimationInterface sets the node size to scale by 1.5.
anim.UpdateNodeCounter (89, 7, 3.4);
With the above statement, AnimationInterface sets the counter with Id == 89, associated with Node 7 with the value 3.4.
The counter with Id 89 is obtained using AnimationInterface::AddNodeCounter. An example usage for this is in src/netanim/examples/resources_demo.cc.
The counter with Id 89 is obtained using AnimationInterface::AddNodeCounter. An example usage for this is in src/netanim/examples/resource-counters.cc.
Step 2: Loading the XML in NetAnim

View File

@@ -21,10 +21,10 @@ def build(bld):
['netanim', 'internet', 'mobility', 'applications', 'uan'])
obj.source = 'uan-animation.cc'
obj = bld.create_ns3_program('dynamic_linknode',
obj = bld.create_ns3_program('colors-link-description',
['netanim', 'applications', 'point-to-point-layout'])
obj.source = 'dynamic_linknode.cc'
obj.source = 'colors-link-description.cc'
obj = bld.create_ns3_program('resources_demo',
obj = bld.create_ns3_program('resources-counters',
['netanim', 'applications', 'point-to-point-layout'])
obj.source = 'resources_demo.cc'
obj.source = 'resources-counters.cc'

View File

@@ -1997,13 +1997,46 @@ AnimationInterface::AnimXmlElement::AnimXmlElement (std::string tagName, bool em
template <typename T>
void
AnimationInterface::AnimXmlElement::AddAttribute (std::string attribute, T value)
AnimationInterface::AnimXmlElement::AddAttribute (std::string attribute, T value, bool xmlEscape)
{
std::ostringstream oss;
oss << std::setprecision (10);
oss << value;
m_elementString += attribute.c_str ();
m_elementString += "=\"" + oss.str () + "\" ";
if (xmlEscape)
{
m_elementString += "=\"";
std::string valueStr = oss.str ();
for (std::string::iterator it = valueStr.begin (); it != valueStr.end (); ++it)
{
switch (*it)
{
case '&':
m_elementString += "&amp;";
break;
case '\"':
m_elementString += "&quot;";
break;
case '\'':
m_elementString += "&apos;";
break;
case '<':
m_elementString += "&lt;";
break;
case '>':
m_elementString += "&gt;";
break;
default:
m_elementString += *it;
break;
}
}
m_elementString += "\" ";
}
else
{
m_elementString += "=\"" + oss.str () + "\" ";
}
}
void
@@ -2102,7 +2135,7 @@ AnimationInterface::WriteXmlUpdateLink (uint32_t fromId, uint32_t toId, std::str
element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
element.AddAttribute ("fromId", fromId);
element.AddAttribute ("toId", toId);
element.AddAttribute ("ld", linkDescription);
element.AddAttribute ("ld", linkDescription, true);
element.CloseElement ();
WriteN (element.GetElementString (), m_f);
}
@@ -2130,9 +2163,9 @@ AnimationInterface::WriteXmlLink (uint32_t fromId, uint32_t toLp, uint32_t toId)
lprop = m_linkProperties[p2];
}
element.AddAttribute ("fd", lprop.fromNodeDescription);
element.AddAttribute ("td", lprop.toNodeDescription);
element.AddAttribute ("ld", lprop.linkDescription);
element.AddAttribute ("fd", lprop.fromNodeDescription, true);
element.AddAttribute ("td", lprop.toNodeDescription, true);
element.AddAttribute ("ld", lprop.linkDescription, true);
element.CloseElement ();
WriteN (element.GetElementString (), m_f);
}
@@ -2143,7 +2176,7 @@ AnimationInterface::WriteXmlRouting (uint32_t nodeId, std::string routingInfo)
AnimXmlElement element ("rt");
element.AddAttribute ("t", Simulator::Now ().GetSeconds ());
element.AddAttribute ("id", nodeId);
element.AddAttribute ("info", routingInfo.c_str ());
element.AddAttribute ("info", routingInfo.c_str (), true);
element.CloseElement ();
WriteN (element.GetElementString (), m_routingF);
}
@@ -2184,7 +2217,7 @@ AnimationInterface::WriteXmlPRef (uint64_t animUid, uint32_t fId, double fbTx, s
element.AddAttribute ("fbTx", fbTx);
if (!metaInfo.empty ())
{
element.AddAttribute ("meta-info", metaInfo.c_str ());
element.AddAttribute ("meta-info", metaInfo.c_str (), true);
}
element.CloseElement ();
WriteN (element.GetElementString (), m_f);
@@ -2212,7 +2245,7 @@ AnimationInterface::WriteXmlP (std::string pktType, uint32_t fId, double fbTx, d
element.AddAttribute ("lbTx", lbTx);
if (!metaInfo.empty ())
{
element.AddAttribute ("meta-info", metaInfo.c_str ());
element.AddAttribute ("meta-info", metaInfo.c_str (), true);
}
element.AddAttribute ("tId", tId);
element.AddAttribute ("fbRx", fbRx);
@@ -2303,7 +2336,7 @@ AnimationInterface::WriteXmlUpdateNodeDescription (uint32_t nodeId)
element.AddAttribute ("id", nodeId);
if (m_nodeDescriptions.find (nodeId) != m_nodeDescriptions.end ())
{
element.AddAttribute ("descr", m_nodeDescriptions[nodeId]);
element.AddAttribute ("descr", m_nodeDescriptions[nodeId], true);
}
element.CloseElement ();
WriteN (element.GetElementString (), m_f);

View File

@@ -520,7 +520,7 @@ private:
public:
AnimXmlElement (std::string tagName, bool emptyElement=true);
template <typename T>
void AddAttribute (std::string attribute, T value);
void AddAttribute (std::string attribute, T value, bool xmlEscape=false);
void Close ();
void CloseElement ();
void CloseTag ();