antithing
(antithing)
July 24, 2015, 10:02am
1
Hi, I am attempting to read through an xml file in ue4 c++.
for example, if my xml is:
<scene>
<asset assetName="asset1">
<transform rx="0.0" ry="0.0" rz="0.0" tx="0.0" ty="5.46978748418" tz="0.0"/>
</asset>
</scene>
I have this:
const FXmlFile file(L"C:/file.xml");
const FXmlNode* SceneNode = file.GetRootNode();
const TArray<FXmlNode*> assetNodes = SceneNode->GetChildrenNodes();
for (int i = 0; i < assetNodes.Num(); i++)
{
const TArray<FXmlNode*> meshNodes = assetNodes*->GetChildrenNodes();
for (int i = 0; i < meshNodes.Num(); i++)
{
FString tag = meshNodes*->GetTag();
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, tag);
}
}
This prints ‘transform’. Which is fine, but how can i access the actual value? meshNodes*->GetContent prints nothing…
Thanks!
antithing
(antithing)
July 24, 2015, 12:28pm
4
I have made it easier on myself, by changing my xml formatting.
So using this:
<scene>
<asset> "group1_GRP"</asset>
<rx>"0.0"</rx>
<ry>"0.1"</ry>
<rz>"2.0"</rz>
<asset> "group2_GRP"</asset>
<rx>"2.0"</rx>
<ry>"2.1"</ry>
<rz>"4.0"</rz>
</scene>
and:
const FXmlFile file(L"C:/file.xml");
const FXmlNode* SceneNode = file.GetRootNode();
FString scenename = SceneNode->GetTag();
//gets all child nodes
const TArray<FXmlNode*> assetNodes = SceneNode->GetChildrenNodes();
this will list every node. BUT, can I step down the levels one at a time? So I can list the ‘asset’ nodes from ‘scene’, then list the ‘rx’, ‘ry’, ‘rz’ nodes inside each ‘asset’ separately?
Thanks!
antithing
(antithing)
July 24, 2015, 12:58pm
5
SOLVED, with a whole bunch of if statements and for loops. Pretty manual way to do it, but it seems to work.
if tag equals ‘asset’, getChildrenNodes, etc.
aloivu
(aloivu)
December 19, 2019, 12:42pm
7
I want to read xml file at runtime with c++. Is this possible with XMLParser.