I can't load xmlsettings with tags using a prefix

Hi, I’m using xmlsettings addon to modify some external file with a given structure. The XML looks like this (I’m removing most of the content):

<cfdi:Comprobante>
  <cfdi:Emisor rfc="APR0412108C5">
  </cfdi:Emisor>
  <cfdi:Addenda>
  </cfdi:Addenda>
<cfdi:Comprobante>

The problem is that when I try to look for the tag  <cfdi:Addenda> using

if(factura.pushTag("cfdi:Addenda"){}

I get the following error:

ofxXmlSettings: pushTag(): tag “cfdi:Addenda” not found

I’ve done tests making an XML file with simple tags like this
 <Addenda> </Addenda>
 and it works, but as I said before the XML I’m trying to modify is an external file and it’s generated by a third party software, so I cannot modify the structure and the prefix of the tags.

My question is: How can I handle and look for tags like this: <tag:tag2></tag:tag2>

Thanks for your help.

try using ofXml instead of ofxXmlSettings, i think it should support tags with namespaces like those

Thanks for the answer Arturo. I changed the code to use ofXml and now I can find tags with a prefix.
Now the problem is that I can’t add values to different child nodes with the same name:

ofFile file;
file.open("001.xml");                   
ofBuffer buffer = file.readToBuffer();  

ofXml fact;
fact.loadFromBuffer(buffer.getText()); 

fact.setTo("cfdi:Addenda");             // go to cfdi:Addenda tag

fact.addChild("cfdi:ItemsFacturados");
fact.setValue("cfdi:ItemsFacturados", "");

for (int i = 0; i < 10; i++) {
    fact.setTo("cfdi:ItemsFacturados");
    fact.addChild("cfdi:OrdenCompra");
    fact.setValue("cfdi:OrdenCompra", ofToString(i));
    fact.addChild("cfdi:item");
    fact.setValue("cfdi:item", ofToString(i));
    fact.setToParent();
}
fact.save();

This code above creates the following XML:

<cfdi:Addenda>
   	<cfdi:ItemsFacturados>
			<cfdi:OrdenCompra>9</cfdi:OrdenCompra>
			<cfdi:item>9</cfdi:item>
			<cfdi:OrdenCompra/>
			<cfdi:item/>
			<cfdi:OrdenCompra/>
			<cfdi:item/>
			<cfdi:OrdenCompra/>
			<cfdi:item/>
			<cfdi:OrdenCompra/>
			<cfdi:item/>
			<cfdi:OrdenCompra/>
			<cfdi:item/>
			<cfdi:OrdenCompra/>
			<cfdi:item/>
			<cfdi:OrdenCompra/>
			<cfdi:item/>
			<cfdi:OrdenCompra/>
			<cfdi:item/>
			<cfdi:OrdenCompra/>
			<cfdi:item/>
		</cfdi:ItemsFacturados>
	</cfdi:Addenda>

So for some reason only the first child is found and populated, the next sibling elements don’t receive the values. I think this is because the xml tags have not an id, so the setValue is done only in the first element.
Do you have an idea of how to fill those values without an id?

Also I tried to build the xml concatenating strings and then saving a final string to a child element, however the < sign is saved in the xml as “&lt ;” and the > sign as “&gt ;” using a unicode literal like \u003C causes an error on the compiler.

Thank you very much for your help.

I believe what you want is something like this:

for (int i = 0; i &lt; 10; i++) {
    fact.setTo("cfdi:ItemsFacturados["+ofToString(i)+"]");
}

or

fact.setTo("cfdi:ItemsFacturados[0]");
// do processing for 1st item, then:
while(fact.setToSibling()) {
    // do processing for each sibling
}

Thanks for the answer again.
I’ve managed to solve it with the following code:

   fact.addChild("cfdi:ItemsFacturados");
fact.setValue("cfdi:ItemsFacturados", "");

for (int i = 0; i < 10; i++) {
    
    fact.setTo("cfdi:ItemsFacturados");
    string nombre;
    nombre = "cfdi:OrdenCompra";
    fact.addChild(nombre);
    
    nombre = "cfdi:Item";
    fact.addChild(nombre);
    
    fact.setToParent();
}


for (int i = 0; i < 10; i++) {
    fact.setTo("cfdi:ItemsFacturados");

    string nombre;
    std:stringstream ss, ss2;
    ss << "cfdi:OrdenCompra[" << ofToString(i) << "]";
    nombre = ss.str();
    fact.setValue(nombre, ofToString(i));
    
    string nombre2;
    ss2 << "cfdi:Item[" << ofToString(i) << "]";
    nombre2 = ss2.str();
    fact.setValue(nombre2, ofToString(i));

    fact.setToParent();
}

Maybe my code is a bit redundant, but it works. I’ll try the while instead. I’ve seen that the behavior for some methods is different; for example I can use xml.setToChild(index) and then apply xml.setAttribute("path", "value") over that child-path with n-index. The attributes are set ok to the child.
However if I try to do the same with xml.setToChild(index) and then xml.SetValue("path", "value") the object can’t find the path. That’s why I used xml.setToParent() at the end of the loop and xml.setTo("path") at the beginning.

Now I’m getting this result that is what I was looking for.

<cfdi:Addenda>
<cfdi:ItemsFacturados>
		<cfdi:OrdenCompra>0</cfdi:OrdenCompra>
		<cfdi:Item>0</cfdi:Item>
		<cfdi:OrdenCompra>1</cfdi:OrdenCompra>
		<cfdi:Item>1</cfdi:Item>
		<cfdi:OrdenCompra>2</cfdi:OrdenCompra>
		<cfdi:Item>2</cfdi:Item>
		<cfdi:OrdenCompra>3</cfdi:OrdenCompra>
		<cfdi:Item>3</cfdi:Item>
		<cfdi:OrdenCompra>4</cfdi:OrdenCompra>
		<cfdi:Item>4</cfdi:Item>
		<cfdi:OrdenCompra>5</cfdi:OrdenCompra>
		<cfdi:Item>5</cfdi:Item>
		<cfdi:OrdenCompra>6</cfdi:OrdenCompra>
		<cfdi:Item>6</cfdi:Item>
		<cfdi:OrdenCompra>7</cfdi:OrdenCompra>
		<cfdi:Item>7</cfdi:Item>
		<cfdi:OrdenCompra>8</cfdi:OrdenCompra>
		<cfdi:Item>8</cfdi:Item>
		<cfdi:OrdenCompra>9</cfdi:OrdenCompra>
		<cfdi:Item>9</cfdi:Item>
	</cfdi:ItemsFacturados>
</cfdi:Addenda>

Thank for your help.