Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * xml_equal
- * Params: Two XML objects
- * Returns: 1 => Objects are equal, 0 => Objects are NOT equal
- */
- int xml_equal(xml *elem1, xml *elem2) {
- // Objects of same type?
- if (elem1->tag == elem2->tag) {
- if (isText(elem1)) {
- // Compare Text contents
- return (strcmp(textVal(elem1),textVal(elem2)) == 0);
- }
- if (isElem(elem1)) {
- // Compare both tags and Lists
- if (strcmp(tag(elem1),tag(elem2)) == 0) {
- return xml_list_equal(children(elem1), children(elem2));
- }
- }
- }
- return 0;
- }
- /**
- * xml_list_equal
- * Params: Two XML Lists
- * Returns:
- */
- int xml_list_equal(xml_list *list1, xml_list *list2) {
- // Compare types
- if (list1->tag == list2->tag) {
- // Both empty list? -> Equal!
- if (isEmpty(list1)) {
- return 1;
- }
- // Both Cons? -> Check their tails for equality
- if (isCons(list1)) {
- return (xml_equal(head(list1),head(list2)) && xml_list_equal(tail(list1),tail(list2)));
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement