Download

reading an xml from c++?

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!

Hello,

According to the documentation you should use an FXmlNode to get the root. The FXmlNode has methods to access tags.

Regards,
Arnaud

Hi, thanks for your reply. As above, I can access the tags. But not the value of the tags.

In the xml:


<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 need to access the ‘rx’, ‘ry’ values.

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!

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.

snip-------

I want to read xml file at runtime with c++. Is this possible with XMLParser.