I need to get details from a xml file. I wrote code in C# but not able to rewrite in C++/CLI.
Code in C#
class cROI
{
public Int16 iX { get; set; }
public Int16 iY { get; set; }
public Int16 iWidth { get; set; }
public Int16 iHeight { get; set; }
public cROI(Int16 iX, Int16 iY, Int16 iWidth, Int16 iHeight)
{
this.iX = iX;
this.iY = iY;
this.iWidth = iWidth;
this.iHeight = iHeight;
Console.WriteLine("{0}, {1}, {2}, {3}", this.iX, this.iY, this.iWidth, this.iHeight);
}
}
In main
List<cROI> m_lAllBoundingRectangle = new List<cROI>();
XDocument xXmlDoc = XDocument.Load("C:/Users/Bradd/Desktop/abc.xml");
var m_cROI = from rect in xXmlDoc.XPathSelectElements("/CLabelSessionContainer/Labels/LabelList/CLabel/VehicleLabel/BoundingRect")
select new cROI(
Int16.Parse(rect.Element("X").Value, System.Globalization.NumberFormatInfo.InvariantInfo),
Int16.Parse(rect.Element("Y").Value, System.Globalization.NumberFormatInfo.InvariantInfo),
Int16.Parse(rect.Element("Width").Value, System.Globalization.NumberFormatInfo.InvariantInfo),
Int16.Parse(rect.Element("Height").Value, System.Globalization.NumberFormatInfo.InvariantInfo)
);
m_lAllBoundingRectangle = m_cROI.ToList();
In C++/CLI i have to do same operation but instead of 4 variables, i decided to Rectangle
class.
Code i wrote in C++/CLI is as follows, in Main()
Rectangle cBoudingRect;
List<Rectangle>^ m_AllBoudingRect = gcnew List<Rectangle>();
XDocument^ xXmlDoc = XDocument::Load("C:/Users/Bradd/Desktop/abc.xml");
auto getData = from rect in System::Xml::XPath::Extensions::XPathSelectElements
("/CLabelSessionContainer/Labels/LabelList/CLabel/VehicleLabel/BoundingRect"); ----> error 1: No suitable overloaded function available, asking for (node, string).
........ & unable to write further part as shown in C# code
as System::Linq is not available, System::XMl::Linq & System::XMl::XPath is used. "from, in, select" are not working....
X,Y,Width, Height are under "./BoudingRect" node....
Thank you !!
Edit : Example for an XML ( Note : Tags/Nodes name may be different but structure is same)
<?xml version="1.0"?>
<CLabelContainer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Labels>
<LabelList>
<CLabel>
<VehicleLabel>
<ImageName>image1.bmp</ImageName>
<BoundingRect>
<X>433</X>
<Y>205</Y>
<Width>39</Width>
<Height>42</Height>
</BoundingRect>
</VehicleLabel>
</CLabel>
.
& So on...
.
<CLabel>
<VehicleLabel>
<ImageName>image20.bmp</ImageName>
<BoundingRect>
<X>425</X>
<Y>305</Y>
<Width>30</Width>
<Height>46</Height>
</BoundingRect>
</VehicleLabel>
</CLabel>
</LabelList>
</Labels>
</CLabelContainer>