Example #1
0
bool c_XMLWriter::t_startattribute(const String& name) {
  if (xmlValidateName((xmlChar*)name.data(), 0)) {
    raise_warning("invalid attribute name: %s", name.data());
    return false;
  }
  int ret = -1;
  if (m_ptr) {
    ret = xmlTextWriterStartAttribute(m_ptr, (xmlChar*)name.data());
  }
  return ret != -1;
}
bool c_XMLWriter::t_startattribute(CStrRef name) {
  INSTANCE_METHOD_INJECTION_BUILTIN(XMLWriter, XMLWriter::startattribute);
  if (xmlValidateName((xmlChar*)name.data(), 0)) {
    raise_warning("invalid attribute name: %s", name.data());
    return false;
  }
  int ret = -1;
  if (m_ptr) {
    ret = xmlTextWriterStartAttribute(m_ptr, (xmlChar*)name.data());
  }
  return ret != -1;
}
Example #3
0
/**
 * xml_writer_write_start_attribute:
 * @writer: A #XmlWriter
 * @name: attribute name
 *
 * Starts an xml attribute on the current element
 */
void
xml_writer_write_start_attribute (XmlWriter   *writer,
                                  const gchar *name)
{
  XmlWriterPrivate *priv;
  
  g_return_if_fail (XML_IS_WRITER (writer));
  
  priv = writer->priv;
  
  if (priv->writer)
    xmlTextWriterStartAttribute (priv->writer, CHAR_TO_XML (name));
}
Example #4
0
void daeLIBXMLPlugin::writeAttribute( daeMetaAttribute* attr, daeElement* element )
{
	static daeChar atomicTypeBuf[TYPE_BUFFER_SIZE];
	
	if (element == NULL)
		return;
	if ( attr->getCount(element) == 0 ) {
		//we don't have a value if its required print it empty else just skip
		if ( attr->getIsRequired() ) {
			xmlTextWriterStartAttribute( writer, (xmlChar*)(daeString)attr->getName() );
			xmlTextWriterEndAttribute( writer );
		}
		return;
	}
	else if ( attr->getCount(element) == 1 ) { 
		//single value or an array of a single value
		char* elemMem = attr->get(element, 0);

		// !!!GAC recoded the suppression logic so you could enable suppressions individually
		if(!attr->getIsRequired())
		{
			// This attribute was not required and might get suppressed
			int typeSize = attr->getType()->getSize();
			if(attr->getDefault() != NULL)
			{
				#if 1
				// The attribute has a default, convert the default to binary and suppress 
				// output of the attribute if the value matches the default.
				// DISABLE THIS CODE IF YOU WANT DEFAULT VALUES TO ALWAYS EXPORT
				if(typeSize >= TYPE_BUFFER_SIZE)
				{
					fprintf(stderr,
							"daeMetaAttribute::print() - buffer too small for default value of %s in %s\n",
							(daeString)attr->getName(),(daeString)attr->getContainer()->getName());
					fflush(stderr);
					return;
				}
				attr->getType()->stringToMemory((daeChar*)attr->getDefault(),atomicTypeBuf);
				if(memcmp(atomicTypeBuf,elemMem,typeSize) == 0)
					return;
				#endif
			}
			else
			{
				#if 1
				// The attribute does not have a default, suppress it if its value is all zeros (binary)
				// DISABLE THIS CODE IF YOU WANT OPTIONAL ATTRIBUTES THAT HAVE A VALUE OF ZERO TO EXPORT
				// Disabling this code may cause some unused attributes to be exported if _isValid is not
				// enabled and properly used.
			int i;
				for(i=0; i<typeSize;i++)
				{
					if(elemMem[i] != 0)
						break;
				}
				if(i == typeSize && attr->getContainer()->getValueAttribute() != attr && 
					attr->getType()->getTypeEnum() != daeAtomicType::BoolType &&
					attr->getType()->getTypeEnum() != daeAtomicType::EnumType )
					return;
				#endif
			}
		}

		// Convert the attribute to a string

		if (attr->getType()->memoryToString(elemMem, atomicTypeBuf,	TYPE_BUFFER_SIZE)== false) {
			fprintf(stderr,
					"daeMetaAttribute::print() - buffer too small for %s in %s\n",
					(daeString)attr->getName(),(daeString)attr->getContainer()->getName());
			fflush(stderr);
		}
					
		// Suppress attributes that convert to an empty string.

		if (strlen(atomicTypeBuf) == 0)
			return;

		// Is this a value attribute or something else?

		if (attr->getContainer()->getValueAttribute() == attr)
		{
			// Always export value attributes
			xmlTextWriterWriteString( writer, (xmlChar*)atomicTypeBuf);
		}
		else
		{
			// Suppress attributes not marked as containing valid values
			// DO NOT TURN THIS ON TILL ALL USER CODE HAS BEEN CHANGED TO SET _isValid OR
			// ATTRIBUTES THAT WERE CREATED/SET BY USER CODE MAY NOT EXPORT.
			#if 0
			// NOTE: even if a value is marked REQUIRED by the schema, if _isValid isn't true it means
			// the value in this parameter was never set and may be garbage, so we suppress it even though it is required.
			// To change this add && !_isRequired to the expression below.
			if(!attr->getIsValid() )
				return;
			#endif
			// Export the attribute name and value
			xmlTextWriterWriteAttribute( writer, (xmlChar*)(daeString)attr->getName(), (xmlChar*)atomicTypeBuf);
		}
	}
	else {
		if (attr->getContainer()->getValueAttribute() != attr)
		{
			xmlTextWriterStartAttribute( writer, (xmlChar*)(daeString)attr->getName() );
		}
		for( int i = 0; i < attr->getCount(element); i++ ) {
			char* elemMem = attr->get(element, i);
			if (attr->getType()->memoryToString(elemMem, atomicTypeBuf,	TYPE_BUFFER_SIZE)== false) 
			{
				fprintf(stderr,
						"daeMetaArrayAttribute::print() - buffer too small for %s in %s\n",
						(daeString)attr->getName(),(daeString)attr->getContainer()->getName());
				fflush(stderr);
			}
			xmlTextWriterWriteFormatString( writer, "%s ", (xmlChar*)atomicTypeBuf );
		}
		if (attr->getContainer()->getValueAttribute() != attr)
		{
			xmlTextWriterEndAttribute( writer );
		}
	}
}