Ejemplo n.º 1
0
// MDW-2013-07-09: [[ RevXmlXPath ]]
int CXMLElement::AttributeCount(char *attributename)
{
	if (!isinited()) return 0;
	CXMLAttribute tattribute;
	int attributecount = 0;
	if (GetFirstAttribute(&tattribute)){
		do {
			if (!attributename || 
				util_strnicmp(tattribute.GetName(),attributename,strlen(attributename)) == 0)
				attributecount++;
		} while (tattribute.GoNext());
	}
	return attributecount;
}
Ejemplo n.º 2
0
//[-------------------------------------------------------]
//[ Public virtual XmlBase functions                      ]
//[-------------------------------------------------------]
bool XmlElement::Save(File &cFile, uint32 nDepth)
{
	/// Get the number of empty spaces
	const XmlDocument *pDocument = GetDocument();
	const uint32 nNumOfSpaces = (pDocument ? pDocument->GetTabSize() : 4) * nDepth;

	// Print empty spaces
	for (uint32 i=0; i<nNumOfSpaces; i++)
		cFile.PutC(' ');

	// Print value
	cFile.Print('<' + m_sValue);

	// Print attributes
	for (XmlAttribute *pAttribute=GetFirstAttribute(); pAttribute; pAttribute=pAttribute->GetNext()) {
		cFile.PutC(' ');
		pAttribute->Save(cFile, nDepth);
	}

	// There are 3 different formatting approaches:
	// 1) An element without children is printed as a <foo /> node
	// 2) An element with only a text child is printed as <foo> text </foo>
	// 3) An element with children is printed on multiple lines.
	if (!GetFirstChild())
		cFile.Print(" />");
	else if (GetFirstChild() == GetLastChild() && GetFirstChild()->GetType() == Text) {
		cFile.PutC('>');
		GetFirstChild()->Save(cFile, nDepth+1);
		cFile.Print("</" + m_sValue + '>');
	} else {
		cFile.PutC('>');

		for (XmlNode *pNode=GetFirstChild(); pNode; pNode=pNode->GetNextSibling()) {
			if (pNode->GetType() != Text)
				cFile.PutC('\n');
			pNode->Save(cFile, nDepth+1);
		}
		cFile.PutC('\n');

		// Print empty spaces
		for (uint32 i=0; i<nNumOfSpaces; i++)
			cFile.PutC(' ');

		// Print value
		cFile.Print("</" + m_sValue + '>');
	}

	// Done
	return true;
}
Ejemplo n.º 3
0
int XGlobalVal::GetAryTString( const char *cNodeName, std::vector<_tstring> *pOutAry ) 
{
	XBREAK( XE::IsEmpty( cNodeName ) );
	auto node = m_nodeRoot.FindNode( cNodeName );
	auto nodeChild = node.GetFirst();
	while( !nodeChild.IsEmpty() ) {
		auto pAttr = nodeChild.GetFirstAttribute();
		if( pAttr ) {
			_tstring strVal = C2SZ( pAttr->Value() );
			pOutAry->push_back( strVal );
		}
		nodeChild = nodeChild.GetNext();
	}
	return pOutAry->size();
}
Ejemplo n.º 4
0
String XmlElement::ToString(uint32 nDepth) const
{
	// Get the number of empty spaces
	const XmlDocument *pDocument = GetDocument();
	const uint32 nNumOfSpaces = (pDocument ? pDocument->GetTabSize() : 4) * nDepth;

	// Print empty spaces
	String sXml;
	for (uint32 i=0; i<nNumOfSpaces; i++)
		sXml += ' ';

	// Print value
	sXml += '<' + m_sValue;

	// Print attributes
	for (const XmlAttribute *pAttribute=GetFirstAttribute(); pAttribute; pAttribute=pAttribute->GetNext())
		sXml += ' ' + pAttribute->ToString(nDepth);

	// There are 3 different formatting approaches:
	// 1) An element without children is printed as a <foo /> node
	// 2) An element with only a text child is printed as <foo> text </foo>
	// 3) An element with children is printed on multiple lines.
	if (!GetFirstChild())
		sXml += " />";
	else if (GetFirstChild() == GetLastChild() && GetFirstChild()->GetType() == Text) {
		sXml += '>' + GetFirstChild()->ToString(nDepth+1) + "</" + m_sValue + '>';
	} else {
		sXml += '>';

		for (const XmlNode *pNode=GetFirstChild(); pNode; pNode=pNode->GetNextSibling()) {
			if (pNode->GetType() != Text)
				sXml += '\n';
			sXml += pNode->ToString(nDepth+1);
		}
		sXml += '\n';

		// Print empty spaces
		for (uint32 i=0; i<nNumOfSpaces; i++)
			sXml += ' ';

		// Print value
		sXml += "</" + m_sValue + '>';
	}

	// Done
	return sXml;
}
Ejemplo n.º 5
0
/*GetAttribute - returns value of specified attribute
attname - name of attribute to look for
isbuffered - if true returns copy of attribute value (must be freed by caller).
returns NULL if specified attribute not found
*/
char *CXMLElement::GetAttributeValue(char *attname, Bool isbuffered)
{
	if (!isinited()) 
		return NULL;

	// OK-2009-01-05: [[Bug 7586]] - Some elements may have a "namespace". This is not regarded by libXML
	// as one of the elements' attributes, but is stored separately. If the required attribute is called 
	// "xmlns", then we retreive the namespace instead of using GetAttributeValue.
	if (strcasecmp(attname, "xmlns") == 0)
	{
		xmlNs *t_namespace;
		t_namespace = NULL;
		GetNamespace(t_namespace);

		if (t_namespace != NULL && t_namespace -> href != NULL)
		{
			return strdup((char *)t_namespace -> href);
		}
	}

	if (isbuffered)
	{
		CXMLAttribute tattribute;
		if (GetFirstAttribute(&tattribute))
		{
			int attributecount = 1;
			do 
			{
				if (!attname || util_strnicmp(tattribute.GetName(), attname, strlen(attname)) == 0)
					return tattribute.GetContent();
			} while (tattribute.GoNext());
		}
	}
	else
		return (char *)xmlGetProp(element, (xmlChar *)attname);
	return NULL;
}
Ejemplo n.º 6
0
// ClearAttrDir
void
ShareAttrDir::ClearAttrDir()
{
	while (Attribute* attribute = GetFirstAttribute())
		RemoveAttribute(attribute);
}